Illegal circular USE: coreemail classes

Hi all

Here is my problem.

I have an agent that gathers email addresses for a mass emailing. When i send the email half the addresses get stuck and they sit in the Mail.box on the server.

When i click on the message i see that half the emails were sent ok but hal the emails are still awaiting sending and the following error appears when i try and open the message.

Illegal circular USE: coreemail classes

Below is the code i use to send the email.

FIRST SUB

Sub CreateEmails

'Set standards

Set Sess= New notessession

Set Db = Sess.CurrentDatabase

ServerName = Db.Server

’ Set Settings Doc Objects

Set SettingsView = Db.GetView( "Administration: Settings" )

Set SettingsDoc  = SettingsView.GetFirstDocument



'check and make sure we can grab the mass email db that is stored in the settingsdoc

Set db2 = Sess.GetDatabase(ServerName,SettingsDoc.MassEmailDBName(0))

If db2.filename = "" Then

	Call BuildErrorEmail		

	Exit Sub

End If



Set Notesview = db.getview("SearchMassEmailsAwaitingProcessing")

Set NotesDocColl = NotesView.GetAllDocumentsByKey("YES",True)

Set NotesDoc = NotesDocColl.GetFirstDocument



While Not NotesDoc Is Nothing

	AddressArray1 = NotesDoc.EmailList1

	AddressArray2 = NotesDoc.EmailList2

	AddressArray3 = NotesDoc.EmailList3

	AddressArray4 = NotesDoc.EmailList4

	AddressArray5 = NotesDoc.EmailList5

	

	AddressArray1 = Arrayappend( AddressArray1, AddressArray2 ) 

	AddressArray1 = Arrayappend( AddressArray1, AddressArray3 ) 

	AddressArray1 = Arrayappend( AddressArray1, AddressArray4 ) 

	AddressArray1 = Arrayappend( AddressArray1, AddressArray5 ) 

	

	AddressArray1 = Fulltrim(AddressArray1)

	CountTo = Ubound(AddressArray1)

	Count = 0

	MaximumAddressesPerEmail = 100

	Set EmailDoc = Nothing

	

	'check and make sure at least 1 item is in the email list

	If NotesDoc.EmailList1(0) = "" Then

		NotesDoc.AwaitingProcessing = ""

		Call NotesDoc.Save(True,False)

	Else

		CurrentAddressCount = 0

		While Count <= CountTo

			

		'IF NO EMAILDOC THEN THIS WILL BE THE FIRST STEP

			If EmailDoc Is Nothing Then

				Call BuildMassEmail

				Call BCCItem.appendtotextlist(AddressArray1(Count))

				NumberOfEmailAddresses = NumberOfEmailAddresses +1

				

		'SEND EMAIL AS THIS IS THE LAST ADDRESS THAT CAN BE PUT ON THE EMAIL

			Elseif (CurrentAddressCount + 1) = MaximumAddressesPerEmail Or Count = CountTo Then

				Call BCCItem.appendtotextlist(AddressArray1(Count))

				'Call EmailDoc.Save(True,False)

				Call EmailDoc.Send(True)

				

				Set EmailDoc = Nothing

				NumberOfEMailsSent = NumberOfEMailsSent + 1

				NumberOfEmailAddresses = NumberOfEmailAddresses +1

				

		'IF WE GET HERE SIMPLY ADD AN ADDRESS	

			Else

				Call BCCItem.appendtotextlist(AddressArray1(Count))

				NumberOfEmailAddresses = NumberOfEmailAddresses +1

			End If

			CurrentAddressCount = CurrentAddressCount + 1

			Count = Count + 1

		Wend

		

		

	End If

	Set NotesDoc = NotesDocColl.GetNextDocument(NotesDoc)

Wend	



If NumberOfEmailsSent > 0 Then

	Call BuildAlertEmail

End If

End Sub

SECOND SUB - THIS BUILDS THE FIELD INFO FOR THE EMAIL

Sub BuildMassEmail

'THERE IS NO SEND IN THIS FUNCTION.

'THAT IS BECUASE WE CONTINUALLY ADD NAMES TO THE BCCITEM UNTIL WE REACH THE MAXIMUM (SET INITIALY TO 100)

Set EmailDoc = New NotesDocument ( db2 )

EmailDoc.Form = "Memo"

EmailDoc.Principal = ServerName

EmailDoc.Subject = NotesDoc.Subject(0)



Set BCCItem = New NotesItem( EmailDoc, "BlindCopyTo", "" )

End Sub

Subject: Illegal circular USE: coreemail classes

This message is due to your USE statements in the Options section. If you are sending a plain email, this should not be an issue. This would only occur if you are including the design in the form when you send it. Make sure that you only USE each script library one time and that one library does not USE the same library that USEs it.

Subject: RE: Illegal circular USE: coreemail classes

Hi Robert

Thanks for the fast reply.

I have no USE statement in the db.

I will explain what i am doing…maybe i am going about this all wrong.

DB 1 has the addresses i need so an agent kicks off grabs the addresses and then opens up DB 2. It creates the email and then attachs the addresses to the bcc field and sends.

Am i going about this the wrong way possibly?

Subject: UI or Backend?

Are you doing all this through the UI? Or are you creating and sending the mail through the back-end classes? Are you specifying a form before mailing? Are you using the Mail database to mail?

If it is through the UI, then there may be something with the mail template or the form you are using in DB2.

If it is through the back-end, make sure when you do a Send, that you don’t attach the form, i.e. notesdoc.Send(FALSE).

See if any of those help.