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!

Lotus Notes E-mail using VB6 12

Status
Not open for further replies.

tenbobmillionaire

Programmer
Jun 13, 2000
27
0
0
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
 
Wow got it to work with out password thanks to Caf. You are the man. Actually I combined the code from CAF and GCMOYN. Now I have password, multiple recipients with a group. And it runs in the backround. You guys are the men. Thanks

 
What about multiple USER support?

My application is a centralized process that needs to be able to send mail on behalf of any one of several users depending on a number of factors.

Any ideas?

-=Bob :)
 
Hi!
I'd like to know how to open saved templates (i.e. templates created using Lotus Notes that is basically a mail item with a logo on it in the left side and some pre defined text and signature) using Visual Basic automation. I mean i'd click a menu item upon which i should be able to read a notes database where in i have several such templates kept in. First i should get a list of all the templates info in a list box and on selecting one of the options the corresponding mail template should be oepned up so that the user can further modify and send that mail item.

Please note that when the mail is sent the template should still be available for next use the next time. Hope you got it.

Any help with an example would be highly appreciated.

thanks,
netizen
 
I would like to develop a VB application to read the Notes mail. I can only find the code to send mail via Notes but how can I read the mails from Notes. Anyone can help?
 
hi guys...many of your posts have helped me, but i want to send individual .html attachments to different users at one time using a loop, using the VB application and Lotus Notes server.
problem is each time a new email is sent, the Lotus Notes password prompt box appears. so how do i bypass the prompt box, so that it doesnt appear each time, and only once when the current user logs in.
Also if i want to send it to different users, will i be able to select the users from the contacts list or it send to all users(like unknownrecipient)

thanks in advance..
 
Ok... I"m trying to do the multiple recipients and cc and attachments, but I can't seem to be able to pass an array.... *sigh*... I've never been good with arrays...

Could someone help with this...

PS. The functions above are good... but it would help if you put the declaration line here as well.... you know, the line that starts "public sub Sent_Notes_Mail(..."... so we can know how you are dimensioning the variables that are being passed.

Thanks

Gcomyn
 
This is my code, I use it in an ActiveX DLL, There is a reference to the Microsoft scripting runtime and
Lotus Notes32.tlb

Option Explicit
'Constants
Private Const APP_NAME As String = "LPSendMail.DLL"

'Error Messages
Private Const ERR_SENDTO As String = "Send to email address has not been set."
Private Const ERR_SUBJECT As String = "Subject of email has not been set."
Private Const ERR_FILE As String = "The following attachment file does not exist."

'Error Numbers
Private Const ERR_NO_SENDTO As Long = 10101
Private Const ERR_NO_SUBJECT As Long = 10102
Private Const ERR_NO_FILE As Long = 10103

'Object Declaration
Private mobjSession As Object
Private mobjNotesDB As Object
Private mobjMailDoc As Object
Private mobjAttachment As Object

'Variable Declaration
Private mstrSendTo As String
Private mstrCopyTo As String
Private mstrSubject As String
Private mstrBody As String
Private mstrAttachFile As String
Private mstrSendToArray() As String


Public Property Let SendTo(strSendTo As String)
Dim lCount As Long
If mstrSendTo <> "" Then
lCount = UBound(mstrSendToArray())
ReDim Preserve mstrSendToArray(lCount + 1)
mstrSendToArray(lCount + 1) = strSendTo
Else
mstrSendTo = strSendTo
ReDim mstrSendToArray(1)
mstrSendToArray(1) = strSendTo
End If
End Property

Public Property Let CopyTo(strCopyTo As String)
mstrCopyTo = strCopyTo
mobjMailDoc.CopyTo = mstrCopyTo
End Property

Public Property Let Subject(strSubject As String)
mstrSubject = strSubject
mobjMailDoc.Subject = mstrSubject
End Property

Public Property Let Body(strBody As String)
mstrBody = strBody
Call mobjAttachment.APPENDTEXT(mstrBody)
End Property

Public Property Let Attachment(strFileName As String)
Dim fso As FileSystemObject
mstrAttachFile = strFileName

'ensure the file exists
Set fso = New FileSystemObject
If fso.FileExists(mstrAttachFile) Then
Set fso = Nothing
Call mobjAttachment.EMBEDOBJECT(1454, "", mstrAttachFile)
Else
Set fso = Nothing
Err.Raise ERR_NO_FILE, APP_NAME, ERR_FILE & " " & mstrAttachFile
End If

End Property

Public Function SendMail() As Boolean

On Error GoTo ErrorHandler

'Ensure the Sendto has been set.
If UBound(mstrSendToArray()) < 1 And mstrSendTo = "" Then
SendMail = False
Err.Raise ERR_NO_SENDTO, APP_NAME, ERR_SENDTO
Exit Function
Else
If UBound(mstrSendToArray()) > 1 Then
mobjMailDoc.SendTo = mstrSendToArray()
Else
mobjMailDoc.SendTo = mstrSendTo
End If
End If

'Ensure the Subject line has been set.
If mstrSubject = "" Then
SendMail = False
Err.Raise ERR_NO_SUBJECT, APP_NAME, ERR_SUBJECT
Exit Function
End If

'Save the message in the users sent folder
mobjMailDoc.SAVEMESSAGEONSEND = True

'Send the email
Call mobjMailDoc.SEND(False)
SendMail = True

Exit Function

ErrorHandler:
SendMail = False
Err.Raise Err.Number, APP_NAME, Err.Description

End Function


Private Sub Class_Initialize()
'Instantiate objects
Set mobjSession = CreateObject("Notes.Notessession")
'try setting the server and maybe the db
Set mobjNotesDB = mobjSession.GETDATABASE("", "")
Call mobjNotesDB.OPENMAIL
Set mobjMailDoc = mobjNotesDB.CREATEDOCUMENT
mobjMailDoc.Form = "Memo"
Set mobjAttachment = mobjMailDoc.CREATERICHTEXTITEM("BODY")
End Sub

Private Sub Class_Terminate()
'Cleanup objects
Set mobjSession = Nothing
Set mobjNotesDB = Nothing
Set mobjAttachment = Nothing
Set mobjMailDoc = Nothing
End Sub
 
Forgot to add more comments about the code I posted

I use an array in the sendto to hold multiple recipients.
When I use it I set the sendto property for each recipient
ie: objMail.SendTo="someone@somewhere.net"
objMail.SendTo="someoneelse@somewhereelse.net"

Unfortunatley I have not found a way to send mail using a different id and password.

But this code(DLL) has worked very well for us.
 
Believe it or not, I had just returned to this issue this morning for a project. My attempts last summer failed, because I was passing the array improperly, like you, GComyn. My mistake was pretty dumb, though, I simply left out the array indicator when I defnined the subroutine.

This is a hybrid of several of the functions and routines previously posted to this thread. I simply took the components most applicable to my need at the time. I appreciate all of the hard work everyone has shared here and do not wish to indicate, at all, that this is mine. I merely wanted to show GComyn my array solution. :)


Sub SendLNEmail(strTo() As String, _ 'Pass recipients list as an array of string values
strCC As String, _
strBCC As String, _
strSubject As String, _
strMsg As String)
'***************************************************************************************************
'**Purpose: This code will send notes through Lotus Notes using VB/VBA OLE Automation
'**Arguments: Describe arguments and valid values.
' strTo INPUT: Pass the list of mail recipients as an array;
' strings are not valid, while they do not produce an error, only the first recipient will receive the note
' Format as fname.i.lname@domain
' strCC INPUT: Pass the list of carbon copy recipients as an array;
' strings are not valid, while they do not produce an error, only the first recipient will receive the note
' Format as fname.i.lname@domain
' strBCC INPUT: Pass the list of blind carbon copy recipients as an array;
' strings are not valid, while they do not produce an error, only the first recipient will receive the note
' Format as fname.i.lname@domain
' strSubject INPUT: Pass the subject line as a string
' strMsg INPUT: Pass the body of the message a string
'
'**Running App: Specifically tested in MS Access 97; should work from any application
'**Destination App: Lotus Notes Release 5.0.10
'**Dependencies: Reference to "Lotus Domino Objects" domobj.tlb
' Lotus Notes must be active and initialized
' **Code can be modified to activate and initialize Lotus Notes but requires the user's specific
' Notes mail server name and mail\USERNAME.nsf filename
'**Creation: 07/30/2003
'**Version Date: 05/03/2004
'**Version: 1.1
'**Author: Gabe Luebben
'**Notes: Additional useful documentation:
' Generally: ' Specifically: ' Copy of Lotus Notes redbook:
' **** DELETED FOR PRIVACY ****
'***************************************************************************************************

Dim lnSess As Object 'Lotus Notes session
Dim lnMail As Object 'Lotus Notes mail database
Dim lnDoc As Object 'Lotus Notes mail document object

Dim str_lnUserName As String 'Current user's Lotus Notes common name

Set lnSess = CreateObject("Notes.Notessession")
str_lnUserName = lnSess.CommonUserName

'Open the mail database.
' If the session has not yet been initialized by a user, the mail server name and the user's "mail\USERNAME.nsf" file must be passed
' Set lnMail = lnSess.GetDatabase("[MailServerName]/CHASE", "mail\[UsersNSFFileName].nsf")
Set lnMail = lnSess.GetDatabase("", str_lnUserName)
Debug.Print lnMail.FilePath

lnMail.Openmail

'Create a new mail document using the memo form
Set lnDoc = lnMail.CreateDocument
lnDoc.Form = "Memo"

'Populate the memo form and send
With lnDoc
.SendTo = strTo 'Pass multiple recipients as "name@domain, name2@domain, name3@domain"
.CopyTo = strCC 'Pass multiple recipients as "name@domain, name2@domain, name3@domain"
.BlindCopyTo = strBCC 'Pass multiple recipients as "name@domain, name2@domain, name3@domain"
.Subject = strSubject 'Currently a required value
.Body = strMsg 'Required value

.FROM = lnSess.CommonUserName 'It's not clear why some programmers used the user's name for the form
.SaveMessageOnSend = True 'Also populated in the .Send action
.Send True, strTo '.Send [SaveCopy] True or False, [Recipients]
End With

'Close all active objects
Set lnSess = Nothing
Set lnMail = Nothing
Set lnDoc = Nothing
End Sub
 
{{{This is a very long post}}}

This is what I came up with. Look near the bottom of this post for how to call it.

Code:
Public Sub SendNotesMail_Multiples(strSubject As String, _
                         strAttachment As Variant, _
                         strTo As Variant, _
                         strCC As Variant, _
                         strBCC As Variant, _
                         strBodyText As String, _
                         Optional bolSaveIt As Boolean = True)
'***************************************************************************************************
'**Purpose:       This code will send notes with attachments through Lotus Notes using VB/VBA OLE Automation
'**Arguments:     Describe arguments and valid values.
'     strSubject    INPUT: Pass the subject line as a string
'     strAttachment INPUT: Pass the list of files to send as an array;
'                          Strings are not valid, while they do not produce an error, only the first attachment will be attached.
'     strTo         INPUT: Pass the list of mail recipients as an array;
'                          strings are not valid, while they do not produce an error, only the first recipient will receive the note
'                          You can send either Email address or your Mailing list names
'     strCC         INPUT: Pass the list of carbon copy recipients as an array;
'                          strings are not valid, while they do not produce an error, only the first recipient will receive the note
'                          You can send either Email address or your Mailing list names
'     strBCC        INPUT: Pass the list of blind carbon copy recipients as an array;
'                          strings are not valid, while they do not produce an error, only the first recipient will receive the note
'                          You can send either Email address or your Mailing list names
'     strBodyText   INPUT: Pass the body of the message a string
'     bolSaveIt     INPUT: Pass a boolean to tell Notes to save the email in your SEND folder or not.
'
'**Running App:     Specifically tested in MS Access 97; should work from any application
'**Destination App: Lotus Notes Release 5.0.10
'**Dependencies:    Reference to "Lotus Domino Objects" domobj.tlb
'                   Lotus Notes must be active and initialized
'                   **Code can be modified to activate and initialize Lotus Notes but requires the user's specific
'                     Notes mail server name and mail\USERNAME.nsf filename
'**Creation:        07/30/2003
'**Version Date:    05/03/2004
'**Version:         1.1
'**Author:          Gabe Luebben
'**Notes:           Additional useful documentation:
'                   Generally: [URL unfurl="true"]http://www.tek-tips.com[/URL]
'                   Specifically: [URL unfurl="true"]http://www.tek-tips.com/gviewthread.cfm/lev2/4/lev3/32/pid/222/qid/38494[/URL]
'                   Copy of Lotus Notes redbook:
'                   **** DELETED FOR PRIVACY ****
'***************************************************************************************************'-------------------------------------------------------------
'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
    Dim i As Integer

'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("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
    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
    With MailDoc
        .Form = "Memo"
        .SendTo = strTo
        .Subject = strSubject
        .Body = strBodyText
        .CopyTo = strCC
        .BlindCopyTo = strBCC
        .SAVEMESSAGEONSEND = bolSaveIt
    End With

'Set up the embedded object and attachment and attach it
    Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
    For i = 0 To UBound(strAttachment)
        If strAttachment(i) <> "" Then
            Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", strAttachment(i), "Attachment")
        End If
    Next i
    
'Send Document
    MailDoc.SEND True, strTo
    
'Clean Up
    Set MailDb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set session = Nothing
    Set EmbedObj = Nothing
End Sub

And here is the code I use to call it:

Code:
Private Sub cmdEmail_Click()
    Dim strFN As String
    Dim strRecipients As Variant
    Dim strCC As Variant
    Dim strSubject As String
    Dim strAttachments As Variant
    Dim strBody As String
    Dim strPath As String
    Dim intCount As Integer
    
    strPath = "G:\BCC\Agency\Stan\Remittances\"
    strRecipients = Array("Loan Ops")
    strCC = Array("NAM Supervisors")
    strSubject = "E-Remit Funded today " & Format(Date, "mm/dd/yyyy") & " - " & Me.txtAgencyName & " (" & Me.txtAgency & ") - " & Format(Me.txtRemitDate, "mm/dd/yyyy") & " - Check: " & Format(Me.txtNTC, "Currency") & " - Total: " & Format(Me.txtTotalRemit, "currency")
    strBody = "Here is the remit for " & Me.txtAgencyName & " (" & Me.txtAgency & ") dated " & Format(Me.txtRemitDate.Value, "mm/dd/yyyy") & " that funded today."
    ReDim strAttachments(0 To 20)
    intCount = 0
    strFN = Dir(strPath & Me.txtAgency & "*.*")
    Do While strFN <> ""
        strAttachments(intCount) = strPath & strFN
        intCount = intCount + 1
        strFN = Dir
    Loop
    ReDim Preserve strAttachments(intCount)
    SendNotesMail_Multiples strSubject, strAttachments, strRecipients, strCC, "", strBody, True
    strFN = Dir(strPath & Me.txtAgency & "*.*")
    Do While strFN <> ""
        Name strPath & strFN As strPath & "To Archive\" & strFN
        strFN = Dir
    Loop
End Sub

I know that the code I use to call the SendNotesMail function does not use multiple recipients, cc's and bcc's... but I wanted them there for when I will need them, and since I was coding for multiple attachments, I might as well do the other.

If anyone can see something in there that can be improved or corrected, Please let me know.

GComyn
 
As you can see, I borrowed Gabe Luebben's declaration comments... and forgot to change the names.... I've forgotten where I got the original code... most likely from here.

Gcomyn
 
Hi Harsh25 ,

What Caf says is correct about using an array for multiple recipients ... what i did is use the vb split function wicht convers a comma separated string (wich has the list of addreses) to an array ! Here is the code .. hope it helps :


Public Sub SendMail(ByVal pFrom As Variant, _
ByVal pFromName As Variant, _
ByVal pTo As Variant, _
ByVal pSubject As Variant, _
ByVal pBody As Variant, _
ByVal pAttachmentFileName As Variant)

On Error GoTo Err_Gen

Dim lMailDB As NotesDatabase 'the mail database
Dim lMailDoc As NotesDocument 'The mail document itself
Dim lAttachME As NotesRichTextItem 'The attachment richtextfile object
Dim lSession As NotesSession 'Notes session
Dim lEmbedObj As Object 'The embedded object (attachment)
Dim lArrTo

Set lSession = New NotesSession

lSession.Initialize

lArrTo = Split(pTo, ",")

Set lMailDB = lSession.URLDatabase

If lMailDB.IsOpen = True Then
'Already open for mail
Else
lMailDB.OPENMAIL
End If

Set lMailDoc = lMailDB.CreateDocument

With lMailDoc
.AppendItemValue "Form", "Memo"
.AppendItemValue "Subject", pSubject
.AppendItemValue "Body", pBody
.AppendItemValue "sendto", pTo
.AppendItemValue "principal", pFromName
.AppendItemValue "ReplyTo", pFrom
.AppendItemValue "Errors-To", "xxxxxx@yahoo.com"
End With

If pAttachmentFileName <> "" Then
Set lAttachME = lMailDoc.CreateRichTextItem("Attachment")
Set lEmbedObj = lAttachME.EmbedObject(1454, "", pAttachmentFileName, "Attachment")
End If

'Send Document
lMailDoc.Send 0, lArrTo

GoTo End_Of_Proc

Err_Gen:

mErrorNbr = Err.Number
mErrorDesc = Err.Description

Set lMailDB = Nothing
Set lMailDoc = Nothing
Set lAttachME = Nothing
Set lSession = Nothing
Set lEmbedObj = Nothing

Err.Raise mErrorNbr, modName & ".SendMail: aqui estoy " + pAttachmentFileName, mErrorDesc

On Error GoTo 0
Resume End_Of_Proc

End_Of_Proc:

Set lMailDB = Nothing
Set lMailDoc = Nothing
Set lAttachME = Nothing
Set lSession = Nothing
Set lEmbedObj = Nothing


End Sub



 
Ok... I've got it working... the mulitples... but I keep getting this error when I open the email in Notes:

Duplicate PUBLIC name V_EMPTY in USE module DocumentConversions


... I'm not sure what is happening... I didn't change anything.. and sometimes, the recipient can't open the file.

Anyone know where I should look to find the answer? Should I take this out of here into a Lotus Notes forum?

Gcomyn
 
Ooh! Ooh! Cool! You guys put in the *other* piece I was going to tackle this week - sending an attachment. Before I go pounding my head against my desk in a frustrated attempt to succeed... would you mind answering this one riddle:

Can I attach ANY type of file via the code you've posted? Or only a rich text object? In other words - can I attach Excel spreadsheets, etc.?

:) :) :)
 
When you pass the entire path of the file that you want to attach, it doesn't matter what type it is... I send pdf files, xls files and text files all the time using my (revised) function.... I"ll post the new function after this.... I had some problems with the one above.

Gcomyn
 
Sweeeeeeet! My boss will be quite the happy camper if I can incorporate that into this revision!
 
I can pass all the fields correctly to Lotus Notes via ShellExecuteA, except the body.

body="whatever" is not picked up if the first field after the mailto, but is concatenated with whatever field precedes it if not the first item after the mailto.

Using Lotus Notes Version 5.0.3

mjvitale@aol.com
 
Here is the code for my revised SendNotesMail. I'm having a problem with it not saving message on send... but in all other cases, it works perfectly.

Code:
Public Sub SendNotesMail_Multiples(strSubject As String, _
                         strAttachment As Variant, _
                         strTo As Variant, _
                         strCC As Variant, _
                         strBCC As Variant, _
                         strBodyText As String, _
                         Optional bolSaveIt As Boolean = True)
'***************************************************************************************************
'**Purpose:       This code will send notes with attachments through Lotus Notes using VB/VBA OLE Automation
'**Arguments:     Describe arguments and valid values.
'     strSubject    INPUT: Pass the subject line as a string
'     strAttachment INPUT: Pass the list of files to send as an array;
'                          Strings are not valid, while they do not produce an error, only the first attachment will be attached.
'     strTo         INPUT: Pass the list of mail recipients as an array;
'                          strings are not valid, while they do not produce an error, only the first recipient will receive the note
'                          You can send either Email address or your Mailing list names
'     strCC         INPUT: Pass the list of carbon copy recipients as an array;
'                          strings are not valid, while they do not produce an error, only the first recipient will receive the note
'                          You can send either Email address or your Mailing list names
'     strBCC        INPUT: Pass the list of blind carbon copy recipients as an array;
'                          strings are not valid, while they do not produce an error, only the first recipient will receive the note
'                          You can send either Email address or your Mailing list names
'     strBodyText   INPUT: Pass the body of the message a string
'     bolSaveIt     INPUT: Pass a boolean to tell Notes to save the email in your SEND folder or not.
'
'**Running App:     Specifically tested in MS Access 97; should work from any application
'**Destination App: Lotus Notes Release 5.0.10
'**Dependencies:    Reference to "Lotus Domino Objects" domobj.tlb
'                   Lotus Notes must be active and initialized
'                   **Code can be modified to activate and initialize Lotus Notes but requires the user's specific
'                     Notes mail server name and mail\USERNAME.nsf filename
'**Creation:        07/30/2003
'**Version Date:    05/03/2004
'**Version:         1.1
'**Author:          Stan Paszt
'**Notes:           Additional useful documentation:
'                   Generally: [URL unfurl="true"]http://www.tek-tips.com[/URL]
'                   Specifically: [URL unfurl="true"]http://www.tek-tips.com/gviewthread.cfm/lev2/4/lev3/32/pid/222/qid/38494[/URL]
'                   Copy of Lotus Notes redbook:
'                   **** DELETED FOR PRIVACY ****
'***************************************************************************************************'-------------------------------------------------------------
'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
    Dim i As Integer

'Set up the objects required for Automation into lotus notes
    Dim MailDb As NotesDatabase        '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 NotesDocument       'The mail document itself
    Dim AttachME As NotesRichTextItem  'The attachment richtextfile object
    Dim LNSession As NotesSession      'The notes LNLNSession
    Dim EmbedObj As Object             'The embedded object (attachment)
    
'Start a LNSession to notes
    Set LNSession = New NotesSession
    LNSession.Initialize
'Get the LNSessions 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 = LNSession.UserName
    MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, _
                 UserName, " "))) & ".nsf"

'Open the mail database in notes
    Set MailDb = LNSession.URLDatabase
    If MailDb.IsOpen = True Then
        'already open for mail
    Else
        MailDb.Open
    End If
    
'set up the new mail document
    Set MailDoc = MailDb.CreateDocument
    With MailDoc
        .AppendItemValue "Form", "Memo"
        .AppendItemValue "From", LNSession.CommonUserName
        .AppendItemValue "SendTo", strTo
        .AppendItemValue "Subject", strSubject
        .AppendItemValue "Body", strBodyText
        .AppendItemValue "CopyTo", strCC
        .AppendItemValue "BlindCopyTo", strBCC
        .AppendItemValue "SaveMessageOnSend", bolSaveIt
    End With

'Set up the embedded object and attachment and attach it
    Set AttachME = MailDoc.CreateRichTextItem("Attachment")
    For i = 0 To UBound(strAttachment)
        If strAttachment(i) <> "" Then
            Set EmbedObj = AttachME.EmbedObject(1454, "", strAttachment(i), "Attachment")
        End If
    Next i
    MailDoc.SaveMessageOnSend = True
'Send Document
    MailDoc.Send True, strTo
    
'Clean Up
    Set MailDb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set LNSession = Nothing
    Set EmbedObj = Nothing
End Sub

Here is how I call it:

Code:
Private Sub cmdEmail_Click()
    Dim strFN As String
    Dim strRecipients As Variant
    Dim strCC As Variant
    Dim strSubject As String
    Dim strAttachments As Variant
    Dim strBody As String
    Dim strPath As String
    Dim intCount As Integer
    Dim strBCC As Variant
    
'The path for the files that will be attached
    strPath = "G:\BCC\Agency\Stan\Remittances\"
'The Recipients of the email. You can send multiple email addresses.
    strRecipients = Array("Loan Ops")
'The Carbon Copies of the email. You can send multiple email addresses.
    strCC = Array("NAM Supervisors")
'The Blind Carbon Copies of the email. You can send multiple email addresses.
    strBCC = Array("")
'This is the subject of the email.
    strSubject = [This is where the subject goes]
'This is the body of the email. For long emails, you may want to split this into several lines.
    strBody = [This is where the body of the email goes]
'Dimension the Attachment array. I arbitrarily chose 20, because I knew there would never be that many for the function.
    ReDim strAttachments(0 To 20)
'This counts how many attachments are being arrayed so we can redim the array afterward.
    intCount = 0
'This is where we get the files and put them in the array. You have to put the entire path in the array, or lotus wont be able to find them.
    strFN = Dir(strPath & Me.txtAgency & "*.*")
    Do While strFN <> ""
        strAttachments(intCount) = strPath & strFN
        intCount = intCount + 1
        strFN = Dir
    Loop
'Redimension the array so there are no empty parts.
    ReDim Preserve strAttachments(intCount)
'Send the information to the SendNotesMail_Multiples procedure.
    SendNotesMail_Multiples strSubject, strAttachments, strRecipients, strCC, strBCC, strBody, True
'This moves the files that I just emailed to another folder, so they don't get sent again.
    strFN = Dir(strPath & Me.txtAgency & "*.*")
    Do While strFN <> ""
        Name strPath & strFN As strPath & "To Archive\" & strFN
        strFN = Dir
    Loop
End Sub

Hope this helps.

Gcomyn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top