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!

Lotus Notes E-mail using VB6 12

Status
Not open for further replies.

tenbobmillionaire

Programmer
Jun 13, 2000
27
EU
Does anyone know how you can send mail to a lotus notes email address using Visual Basic 6? What reference or object or whatever do I need to include in my project and does anyone have any example code.
thanks in advance
Mick
 
When you send e mail, it does not matter what E Mail application the recipient is using.

If you mean send an e mail using Lotus Notes (instead of Outlook.Application) on the senders machine, then ....

I have heard that Lotus Notes have developed an object that can be used in VB. However, I have not tried any of this. From what I have heard, it sounds like the difficult bit is knowing how Lotus Notes is structured - pretty much the same as using the Outlook object model - then you can create e mail using Lotus Notes instead of Outlook.

Simon
 
Yes I want to send an email using Lotus Notes but don't know what object/reference to use. Basically I am after a Lotus Notes version of the Outlook object (if it exists).
Thanks
Mick
 
Hi

If you have version 5 or higher then you're in luck because you can use COM.
If you have a lower version then you're doomed to use OLE Automation on Lotus.
I have Notes 4.6 (ugh - I hate Lotus!)
THe problem with OLE Automation is that the software must be on your system & you have no Intellisense to help you out so you have to look at White Papers & search (& pray) that you get some sort of object tree to show you what the yell is going on! >:-< (had to get that off me chest ;-) )

If you have release 5.0.2b the component's name is
domobj.tlb
(I can't help you with an example though since I don't have that version)

If you doomed like me with Release 4.6 or less
than 5.0.2b then
Code:
Private Sub Command1_Click()

   Dim sDatabase  As String
   Dim sServer    As String

   sServer = &quot;YourServer/GoesHere&quot;
   sDatabase = &quot;Mail\...\somename.nsf&quot;

   Dim Session    As Object
   Set Session = CreateObject(&quot;Notes.NotesSession&quot;)

   Dim DataBase   As Object
   Set DataBase = Session.GETDATABASE(sServer, sDatabase)
   DataBase.OpenMail

   Dim Document   As Object
   Set Document = DataBase.CREATEDOCUMENT()

   Document.Form = &quot;Memo&quot;

   With Document
      .SendTo = &quot;johndoe@unknown.com&quot;
      .Subject = &quot;Test OLE automation&quot;
      .Body = &quot;Testing OLE&quot;
      .From = Session.COMMONUSERNAME
      .SaveMessageOnSend = True
      .Send True
   End With

End Sub
 
How do you pass a password to open a Lotus Notes mailbox?
 
This is great!

I've been looking on the net for this code.. and I found several different versions. I have one that will let you add attachments.

What I'm looking for is how to add CC and BCC as well as set the receipt return flag.

If you can help, That would be GREAT!!!!

Gwydion
 
Hi all

I am also trying to send an email through Lotus Notes R5 from within a MS Access 97 VBA procedure...if I were to use
the code above, how do I find out the server and database name of my users?

If I define sServer = &quot;&quot; and sDatabase = &quot;&quot; then I get error message number 7000 - 'signature on document is invalid (inconsistent field signatures)'..

Thanks
Klopper
 
GComyn, if I understand your above comments you happend to have a copy of the code with add attachments.I have been looking for such a thing for a bit of time, can you please send me the code as I have to write an app that runs in the windows startup procedure.

Thanks

[afro]Zeroanarchy Experience is a wonderful thing. It enables you to recognize a mistake
when you make it again.
 
Here is the code, If anyone can figure out how to add the CC or BCC, as well as get it to copy the sent email into the 'sent' folder, that would be great!

The Code:

Public Sub SendNotesMail(strSubject As String, _
strAttachment As String, _
strRecipient As String, _
strBodyText As String, _
bolSaveIt As Boolean)
'-------------------------------------------------------------
'This public sub will send a mail and attachment if neccessary to the recipient including
'the body text.
'Requires that notes client is installed on the system

'Set up the objects required for Automation into lotus notes
Dim MailDB As Object 'the mail database
Dim UserName As String 'the current user's notes name
Dim MailDBName As String 'The current user's notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'Teh notes session
Dim EmbedObj As Object 'The embedded object (attachment)

'Start a session to notes
Set Session = CreateObject(&quot;Notes.Notessession&quot;)

'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
MailDBName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, _
UserName, &quot; &quot;))) & &quot;.nsf&quot;

'Open the mail database in notes
Set MailDB = Session.getdatabase(&quot;&quot;, 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 = &quot;Memo&quot;
MailDoc.sendto = strRecipient
MailDoc.Subject = strSubject
MailDoc.body = strBodyText
MailDoc.savemessageonsent = bolSaveIt

'Set up the embedded object and attachment and attach it
If strAttachment <> &quot;&quot; Then
Set AttachME = MailDoc.createrichtextitem(&quot;Attachment&quot;)
Set EmbedObj = AttachME.embedobject(1454, &quot;&quot;, strAttachment, &quot;Attachment&quot;)
' MailDoc.createrichtextitem (&quot;Attachment&quot;)
End If

'Send Document
MailDoc.send 0, strRecipient

'Clean Up
Set MailDB = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub



 
GComyn

To CC or BCC use

MailDoc.copyto = strCC

and

MailDoc.blindcopyto = strBCC

I am sure you can handles all the other places you need to add Dims and stuff. Enjoy.
 
I have a question to add. How do you send to multiple recipients. I tried for example:


strRecipient = &quot;Username1, Username2&quot;

but that errored. Any ideas.

Also. If you go into a lotus email and click database properties you will find the list of properties (Sendto, Copyto, BlindCopyTo, etc.) That is where I found your answer GComyn.

Thanks

Matt
 
My customer, who uses notes, would like an email output from the programme. I don't use notes and can't figure out where to get Notes.Notessession object from so I can compile. I have notes 5 beta ! from a cover disc but cannot find anywhere where this object is. I really don't want to install notes 5 beta on my pc.

Peter Meachem
peter @ accuflight.com
 
Mr Murphy has pointed out to me that I asked my question in a similar thread and not this one. Apologies to all.

I'd still really like an answer mind! Peter Meachem
peter @ accuflight.com

 
In response to mcoko RE: Multiplke recipients ;-) It's exactly 2 years since I replied to the original thread but here goes. Since then I've upgraded to 5.08.

Dim lotSession As Domino.NotesSession
Dim lotDocument As Domino.NotesDocument
Dim lotDatabase As Domino.NotesDatabase
Dim vRecipients As Variant

Set lotSession = New Domino.NotesSession

With lotSession
.Initialize &quot;xxpasswordgoesherexx&quot; 'or u can use
'an inputbox
End With

Set lotDatabase = _
lotSession.GetDbDirectory(&quot;xxx&quot;).OpenMailDatabase

With lotDatabase
If Not .IsOpen Then
.Open
End If
End With

vRecipients = Array( &quot;name@domain&quot;, _
&quot;anothername@somedomain&quot;, _
&quot;recipient@domain&quot; _
)

Set lotDocument = lotDatabase.CreateDocument()

With lotDocument
.AppendItemValue &quot;Form&quot;, &quot;Memo&quot;
.AppendItemValue &quot;Subject&quot;, &quot;Testing&quot;
.AppendItemValue &quot;Body&quot;, &quot;Testing&quot;
.Send False, vRecipients
End With

Set lotDocument = Nothing
Set lotDatabase = Nothing
Set lotSession = Nothing

Hope this helps :)

caf

PS: You can use Redim Preserve with dynamic array if u don't know who the recipients are or how many of them at the time of compilation.
 
In response to Klopper RE:Getting the server & dbnames from the user's settings without prompting the user for that information requires a simple adjustment to the code I posted above.

Instead of using the line:

Set lotDatabase = _
lotSession.GetDbDirectory(&quot;xxx&quot;).OpenMailDatabase


Replace it with the following code:

Set lotDatabase = lotSession.URLDatabase

Then the only information you can prompt your user for is the password and that you can prompt for with an inputbox.

Hope this helps :)

caf

 
In response to Peter Meachem RE: NotesSession object.
As far as Notes 5 Beta goes, I can't say for certain that the type library would exist on your pc after installation as it's a beta and I don't have it to test with. What you need to understand is that if you're going to develop for Notes, you're going to have to install the version your users are going to have on their pc's in order to accurately develop for them. Failing to do so would result in you coding in the dark at those stages and you're going to have some difficulty ironing out all the creases ;-). Anyway, once you have Notes 5.02b or higher installed then you'll find the typelib on your system: domobj.tlb. You can then set a reference to it thru VB and you'll have the object model available to you.

Hope this helps :)

caf
 
Thanks caf.

I had a thought. Presumably shellexecute will start up whatever the user has for email. I know with OE I can add a subject and message into the shellexecute call. Does anyone know if I can add an attachment and if that works with notes.

I can't find any relevant information elsewhere one way or the other. Peter Meachem
peter @ accuflight.com

 
Ok for those of you who are more expereinced in lotus notes do you know if this method would work in notes?? I am trying to come up with a universal method of emailing rather than write a executable file for every type of email system also the idea of having to install notes for each version my clients have will become a problem.

Thanks for your feedback.



Without Oulook (My preferred method)

Reference the CDO 1.21 object from your references section in the VB IDE


Private Sub SendMail(tBody As String, tSubject As String)

Dim objSession As MAPI.Session
Dim objmessage As MAPI.Message
Dim objRecipient As MAPI.Recipient
Dim objAttach As MAPI.Attachment


'Create the Session Object
Set objSession = CreateObject(&quot;mapi.session&quot;)




'Logon using the session object
'Specify a valid profile name if you want to
'Avoid the logon dialog box
'If you don't include a profilename then a dialog is popup requesting one
objSession.Logon profileName:=&quot;MS Exchange Settings&quot;


'Add a new message object to the OutBox
Set objmessage = objSession.Outbox.Messages.Add

'Set the properties of the message object
objmessage.Subject = tSubject
objmessage.Text = tBody
'Popup the global addresslist to select your recipients
'Force the resoluion of the named recipients
Set objmessage.Recipients = objSession.AddressBook(, &quot;Select Recipients&quot;, , True, , &quot;>>&quot;)

'To add attachments
Set objAttach = objmessage.Attachments.Add
objAttach.Name = &quot;testing&quot; 'Pass your own name
objAttach.Source = &quot;C:\Boot.ini&quot; 'Pass in your own filename
objAttach.Type = CdoFileData 'This is the Default



'Send the message
objmessage.Send showDialog:=False


'Logoff using the session object
objSession.Logoff

End Sub [afro]ZeroAnarchy
Experience is a wonderful thing. It enables you to recognize a mistake
when you make it again.

 
Does anyone know how to pass a password from the VB code to the Lotus Database. I want my program to run offline and when it open the mail DB I get prompted for the password. Is it possible to pass the password so as not to be prompted. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top