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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automated VB Email App using Notes

Status
Not open for further replies.

ricklivesey

Programmer
Aug 28, 2002
1
GB
Hi,

I'm new to all this, I've just got a few simple questions. I'm developing an automated server app in VB that needs to be able to email using Lotus.

1) Does Notes have to be installed on the server, or can I just include the COMs in my VB package to be able to send emails?

2) What's the deal with the databases? Are these set up when a new user is added to the Notes system? Must I access one of these to be able to send an email?

3) Do I have to specify the mailfile server name and mailfile name to be able to send emails? Or can I just use the profile, (including the LotusNotes Mail service), that I set up, in control panel?

Any help / advice would be appreciated.

Thanks
Rick
 
Hi Rick

I got this code from to use in Access 97, and it allows me to mail reports directly from my Access database. It works really well.

The pre-requisite is that the Notes client is installed and running on the machine running the code. The code itself accesses the mail database, as you can see.

This doesn't quite answer your problem directly, but it may give you a starting point.

Public Sub SendNotesMail(Subject As String, Attachment As String, Recipient As String, BodyText As String, SaveIt As Boolean)

'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim Username As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
Username = Session.Username

'MsgBox "Username is " & UserName, vbOKOnly, "Username"

MailDbName = Left$(Username, 1) & Right$(Username, (Len(Username) - InStr(1, Username, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.ISOPEN = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.Body = BodyText
MailDoc.SAVEMESSAGEONSEND = SaveIt
'Set up the embedded object and attachment and attach it
If Attachment <> &quot;&quot; Then
Set AttachME = MailDoc.CREATERICHTEXTITEM(&quot;Attachment&quot;)
Set EmbedObj = AttachME.EMBEDOBJECT(1454, &quot;&quot;, Attachment, &quot;Attachment&quot;)
MailDoc.CREATERICHTEXTITEM (&quot;Attachment&quot;)
End If
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.SEND 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub

Hope this helps.

Colin
 
you do need to have the client installed on the box that you're running your code on afaik.
Woonjas
IRC: #notes on EFNet
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top