Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send Mail using an external file

Status
Not open for further replies.

rudyboy

Programmer
Oct 16, 2003
49
0
0
PH
Hi Everyone,

I want to send a mail using an external file(example, TXT file). Inside this file, on the first line is the email address of the recipient, second line is the subject and the remaining will be the body. This procedure will work like an agent because it will check a certain directory for the TXT file and it will automatically send the mail using the text file's content.

Thanks

Rudy



 
You will need to create an agent in either LotusScript or Java to achieve this in a controlled way. The use of @MailSend can be tested, but it is a little bit to 'uncontrollable' to be 100% trusted.

Since it will be using random file names the file directory must be read with 'wildcards' (in e.g. '*.txt') to get the complete list. For this, use the DIR function:

Dim filepath as string, filename as string
filepath$ = "c:\\whatz\\isnehm\\*.txt"

filename$ = DIR$(filepath$)
while filename$ <> ""
'Do all other functions here pr filename
Call TranslateFileAndSendMail(filename$, db as NotesDatabase)
filename$ = Dir$()
wend

SUB TranslateFileAndSendMail(filename as string)
' This will NOT be a complete function, but outline the IDEA
Dim Memo as New NotesDocument(db)
Dim rtf as NotesRichTextItem
Dim fileline as string
Dim instream as NotesStream
Set instream = db.Parent.CreateStream()
Call instream.Open(filename$)
memo.form = "Memo"
' read the first line
memo.SendTo = instream.ReadText(STMREAD_LINE, EOL_PLATFORM)
' read the second line
memo.Subject = instream.ReadText(STMREAD_LINE, EOL_PLATFORM)
' Create the body...
Set rtf = memo.CreateRichTextItem("Body")
while (Not (instream.IsEOS))
fileline$ = instream.ReadText(STMREAD_LINE, EOL_PLATFORM)
rtf.AppendText(fileline$)
rtf.AddNewLine(1)
wend
Call instream.Close()
Call memo.Send(true)
END SUB

As said, not tested, and will probably need some mods, but should not be too far from what you are looking for...





Brgds,

TrooDOS
 
I was able to create an agent to get the external file and send it to the address indicated inside the text file.

I moved it to our domino server but unfortunately it was not sending emails. When I run the agent manually from the menu it was sending mail but when I run it on a scheduled time, it wasnt sending any mails. What can be the problem?

Please help.

I am attaching the code




Thanks a lot



 
Check the following: Is the Domino server running as a SERVICE? If 'yes', this is the first thing to check: The FILE and LAN rights of the user running the service.

If the default is used, there is limited/no file rights available, and to verify this, stop the service, start the server as an application (nserver.exe) and see if the agent runs better then.

Brgds,

TrooDOS
 
Hi,

I placed a messagebox in my agent. when I ran it, it is working ok. But when I scheduled it, i thisn lotus note is not executing the program.

I am attaching the program, it is working OK if I ran it manually but when scheduled it, it is not.

Please help. Thanks



Sub Initialize

Dim filepath As String, filename As String, ls_root As String



ls_root = "c:\textfile\"
filepath$ = "c:\textfile\*.txt"


filename$ = Dir$(filepath$)
While filename$ <> ""
Call TranslateFileAndSendMail(ls_root + filename$) filename$ = Dir$()
Wend
End Sub


Sub TranslateFileAndSendMail(filename As String)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim newdoc As notesdocument
Dim rtitem As NotesRichTextItem
Dim rtf As NotesRichTextItem
Dim fileline As String,sendto As String

Dim txt As String
Dim fileNum As Integer
Dim counter As Integer
Dim countRec As Integer
' Get an unused file number so LotusScript can open a file.
fileNum% = Freefile()
counter% = 0
'countrec = 1

Open filename For Input As fileNum

' prepare mail
Set db = session.currentdatabase
Set newDoc = New notesDocument(db)
Set rtitem = New NotesRichTextItem(newDoc, "Body" )
Call rtitem.AddNewLine( 3 )

Do While Not Eof(fileNum%)
' Read each line of the file.
Line Input # fileNum, txt$
' Increment the line count.
counter% = counter% + 1
countrec = countrec + 1

If countrec = 1 Then
sendto = txt$
End If

'body of e-mail
If countrec > 1 Then
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendText( txt$)
End If

Loop

'send mail to recipient
newDoc.Subject = "sample"
newDoc.SendTo = sendto
Call newDoc.Send( False,sendto)

Close fileNum%
Kill filename

End Sub


 
And you have the rights to run agents, incl the rights of "Run restricted LotusScript/Java agents" and "Run unrestricted methods and operations" on the Domino server? (See the security tab for the server)
You need file access here, hence you (or the user / server 'run as' set in agent props) will need "unrestricted" access...

Brgds,

TrooDOS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top