Agent: Modify mail and send/forward with the original senders name

Hi!I have the following problem:

We have certain mailgroups containing phonenumbers, used to send sms-messages to our employees. We recently changed sms-system because of the need to have delivery reports, but the new system cannot handle group names. It requires either a complete list of phonenumbers in the “SendTo” field or an attached file in the body field of the message containing all the phonenumbers in the group.

Since we obviously want to continue using our groups we are trying to solve the problem by getting a rule on the server to send all mails aimed at certain groups to a database, where an agent then should attach the file in question and send it on its way.

The rule on the server is done, but the agent in the database isn’t doing it’s job. I’ve done a manual agent with the following code:

Sub Initialize

On Error Goto ExitFile

'Main code

Dim ExportNamn As String	

Dim db As New NotesDatabase("","")

Dim view As NotesView

Dim session As New NotesSession

Dim collection As NotesDocumentCollection	

Dim coldoc As NotesDocument

Dim doc As NotesDocument

Dim NChar As String

Dim FileNum As Integer

Dim FileName As String

Dim x As Integer

Dim phonenumber As String

Dim rtitem As NotesRichTextItem

Dim object As NotesEmbeddedObject





Dim tecken_ut(2) As String

tecken_ut(0) = "<"

tecken_ut(1) = ">"

tecken_ut(2) = "@pixie.se"

'--------------------------------------------------------------------------------------------------------------------

’ Name and path of the temporary saved file

ExportNamn = "C:\NummerFil.txt"

’ Which database

Call db.Open( "MMADOM10", "pagen_gemensam/it_avd/pixiemail.nsf" )	

’ View to get the document

Set view = db.GetView("Inkorg2")	

'--------------------------------------------------------------------------------------------------------------------

Set collection = Nothing	

'Create txt-file and open for writing

FileNum = Freefile()

FileName = ExportNamn

Open FileName For Output As FileNum

'Set document and body field

Set doc = view.GetFirstDocument

Set rtitem = doc.GetFirstItem("Body")	

'Get all the recipients, remove illegal characters and print to the file

x = 0

Forall num In doc.Recipients

	phonenumber = Replace(Cstr(doc.Recipients(x)), tecken_ut, "")

	Print # fileNum%, phonenumber

	x = x+1

End Forall

'Add a new line, attach the file, set a lot of fields, save the document and send the email

Call rtitem.AddNewLine(1)

Set object = rtitem.EmbedObject 	( EMBED_ATTACHMENT, "", "c:\NummerFil.txt")

'Set a lot of from-fields

doc.Principal = "test1@domain1.com" 'stays

doc.From = "test1@domain1.com" 

doc.AltFrom = "test1@domain1.com"

doc.SendFrom = "test1@domain1.com" 'stays

doc.INetFrom = "test1@domain1.com"

doc.tmpDisplaySentBy = "test1@domain1.com" 'stays

doc.tmpDisplayFrom_Preview = "test1@domain1.com" 'stays

doc.DisplaySent = "test1@domain1.com" 'stays

doc.Form = "Memo"

Call doc.Save( True, True )

doc.SendTo = "Frank Andersson"

Call doc.Send( False )



Close #FileNum	

Exit Sub 

ExitFile:

Print "I errorsub"



Exit Sub

End Sub

The file and it’s contents are created and attached successfully, but there are two problems (so far) :

  1. When I create an agent that runs “After new mail has arrived” (of course replacing the string “ExportNamn” to a server path) the agent runs but can’t find any documents to run on. Why?

  2. When I run it manually, the original sender is overwritten with my name. Is there any way to keep the original sender in the “From”-field when “forwarding” the modified email? This is a must since all the delivery reports of the sms-messages should go to the original sender.

Any tips are appreciated. Any other way to tackle this problem? Thanks in advance! =)

Regards

Frank

Subject: Agent: Modify mail and send/forward with the original senders name

I’ve never done this before but if I understand your problem correctly you could try this approach, which I recently came across while searching another issue in this forum:

instead of using Call doc.Send( False ), replace with this:

Dim mbox as NotesDatabase

Set mbox = session.GetDatabase(db.Server, “mail.box”)

Call doc.CopyToDatabase(mbox)

Subject: RE: Agent: Modify mail and send/forward with the original senders name

Hi Paul and thank you for your response!

The mailadress I’m suppose to send the sms-messages to are external (outside our domino enviroment) so I don’t think I can copy the document instead of sending it. Can I?

Regards

Frank

Subject: RE: Agent: Modify mail and send/forward with the original senders name

yes, you are copying it to mail.box which the server will pick it up from there and send it out.