VB Code to add c.c Email addresses into automated email. (1 Viewer)

southwestgooner

Registered User.
Local time
Today, 08:30
Joined
May 14, 2009
Messages
27
Hi All,
Hope your all having a good day.
This newbie to writing VB Code is in need of some help. I am a quick learner so hopefully this will add another string to my bow !

I have an automated email system (Lotus Notes) in a Access database I have created and am looking for the code needed to add up to 3 c.c addresses into an email prior to sending automatically.

The code I have to send the email to the To: individual is all working but can someone tell me what code I need to add and where for the c.c addresses of which there could be 1, 2 or 3. The control for To address is EmailTo = CustCopyEmail
The controls for the 3 c.c emails are cc_EmailAddress, cc_EmailAddress1 and cc_EmailAddress2.

Here's the code I have:

Private Sub SEND_CC_Click()
' Set up the objects required for Automation into Lotus Notes.

Dim Maildb As Object 'The mail database.
Dim Session As Object 'The Lotus Notes session.
Dim MailDoc As Object 'The mail document itself.
Dim UserName As String 'The current users Lotus Notes name.
Dim Subject As Object 'The message subject text.
Dim Body As Object 'The message body text.
Dim ECNNo As String 'The ECN No that has been updated.
Dim FullName As String 'The originars full name.
Dim EmailTo As Variant 'The email address of the originator or recipient.

' Set Email Address from form control.
EmailTo = CustCopyEmail

' Start a session to notes.
Set Session = CreateObject("Notes.NotesSession")

' Open the mail database in notes.
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

' Create the mail document.
Set MailDoc = Maildb.CREATEDOCUMENT
Call MailDoc.ReplaceItemValue("Form", "Memo")

' Set the recipient.
Call MailDoc.ReplaceItemValue("SendTo", EmailTo)

' Set subject.
Call MailDoc.ReplaceItemValue("Subject", "Issue Sheet " & Me.M_IssSheetID & " actions required.")

' Create and set the Body content.
Set Body = MailDoc.CREATERICHTEXTITEM("Body")
Call Body.APPENDTEXT("Issue Sheet No " & Me.M_IssSheetID & " is available for your actions. Please view the Issue sheet and fill in any relevant required info. For your info the change(s) requested are '" & Me.ChangeGen & "'")

' Call Body.ADDNEWLINE(2)
' Call Body.EMBEDOBJECT(1454, "", "C:\filename", "Attachment")

' Example to save the message (optional).
MailDoc.SAVEMESSAGEONSEND = True

' Send the document.
Call MailDoc.ReplaceItemValue("PostedDate", Now())

' Gets the mail to appear in the Sent items folder.
Call MailDoc.SEND(False)

' Clean Up.
Set Maildb = Nothing
Set MailDoc = Nothing
Set Subject = Nothing
Set Body = Nothing
Set Session = Nothing

' Confirmation messages.
MsgBox "Message has been transferred to Notes and sent."
MsgBox "Check Lotus Notes inbox to ensure no delivery failure."
End Sub

Many thanks in anticipation of a swift resolution to this.

Cheers,
Steve.
 

southwestgooner

Registered User.
Local time
Today, 08:30
Joined
May 14, 2009
Messages
27
What's wrong with this current code ?
It seems to be going to the first c.c address but not the other two !

Private Sub SEND_CC_Click()
' Set up the objects required for Automation into Lotus Notes.

Dim Maildb As Object 'The mail database.
Dim Session As Object 'The Lotus Notes session.
Dim MailDoc As Object 'The mail document itself.
Dim UserName As String 'The current users Lotus Notes name.
Dim Subject As Object 'The message subject text.
Dim Body As Object 'The message body text.
Dim ECNNo As String 'The ECN No that has been updated.
Dim FullName As String 'The originars full name.
Dim EmailTo As Variant 'The email address of the customer copy or To: recipient.
Dim cc1EmailTo As Variant 'The email address of the customer copy first c.c: recipient.
Dim cc2EmailTo As Variant 'The email address of the customer copy second c.c: recipient.
Dim cc3EmailTo As Variant 'The email address of the customer copy third c.c: recipient.

' Set To: Email Address from form control.
EmailTo = CustCopyEmail

' Set c.c: Email Addresses from form control.
cc1EmailTo = cc_EmailAddress
cc2EmailTo = cc_EmailAddress1
cc3EmailTo = cc_EmailAddress2

' Start a session to notes.
Set Session = CreateObject("Notes.NotesSession")

' Open the mail database in notes.
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

' Create the mail document.
Set MailDoc = Maildb.CREATEDOCUMENT
Call MailDoc.ReplaceItemValue("Form", "Memo")

' Set the recipient.
Call MailDoc.ReplaceItemValue("SendTo", EmailTo)

' Set the c.c. recipient(s).
ccRecipient = cc1EmailTo & ", " & cc2EmailTo & ", " & cc3EmailTo
Call MailDoc.ReplaceItemValue("CopyTo", ccRecipient)

' Set subject.
Call MailDoc.ReplaceItemValue("Subject", "Issue Sheet " & Me.P_IssSheetID & " actions required.")

' Create and set the Body content.
Set Body = MailDoc.CREATERICHTEXTITEM("Body")
Call Body.APPENDTEXT("Issue Sheet No " & Me.P_IssSheetID & " is available for your actions. Please view the Issue sheet and fill in any relevant required info. For your info the change(s) requested are '" & Me.ChangeGen & "'")

' Call Body.ADDNEWLINE(2)
' Call Body.EMBEDOBJECT(1454, "", "C:\filename", "Attachment")

' Example to save the message (optional).
MailDoc.SAVEMESSAGEONSEND = True

' Send the document.
Call MailDoc.ReplaceItemValue("PostedDate", Now())

' Gets the mail to appear in the Sent items folder.
Call MailDoc.SEND(False)

' Clean Up.
Set Maildb = Nothing
Set MailDoc = Nothing
Set Subject = Nothing
Set Body = Nothing
Set Session = Nothing

' Confirmation messages.
MsgBox "Message has been transferred to Notes and sent."
MsgBox "Check Lotus Notes inbox to ensure no delivery failure."
End Sub

What's right and what's wrong please ?
Can anyone please edit and reply with code that will do what I want it to do ??

Thanks in anticipation of a satisfactory conclusion to my problem.
Cheers,
Steve.
 
Last edited:

Minty

AWF VIP
Local time
Today, 08:30
Joined
Jul 26, 2013
Messages
10,374
You are putting a comma between the cc email addresses, I think you need to use a semicolon ;
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:30
Joined
Sep 21, 2011
Messages
14,445

southwestgooner

Registered User.
Local time
Today, 08:30
Joined
May 14, 2009
Messages
27
Hi,
Thanks for the replies. I'm not at work due to holiday for next couple of weeks and will look into your resolutions when I return in a coupe of weeks time.
Hope the array will resolve my problem will thank if it does and reply if it doesn't !
Cheers,
Steve.
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:30
Joined
Sep 21, 2011
Messages
14,445
Well two separate posts have stated that the array method works. :)

Strange way of doing things, but if it works :banghead:
 

southwestgooner

Registered User.
Local time
Today, 08:30
Joined
May 14, 2009
Messages
27
Hi all,
Back from holiday in sunny Spain !
Have added the Array for the c.c. addresses but still not working !

Current code below can anyone see why the email goes to the 'To' address but not to any of the 'c.c.' addresses ??? :banghead:

Private Sub SEND_CC_Click()
' Set up the objects required for Automation into Lotus Notes.

Dim Maildb As Object 'The mail database.
Dim UserName As String 'The current users Lotus Notes name.
Dim MailDbName As String 'The current users notes mail database name
Dim MailDoc As Object 'The mail document.
Dim Session As Object 'The Lotus Notes session.
Dim EmailTo As Variant 'The email address of the customer copy or To: recipient.
Dim CopyTo As Variant 'Determines the c.c. Addresses.
Dim Subject As Object 'The message subject text.
Dim Body As Object 'The body of the message text.


' Set To: Email Address from form control.
EmailTo = CustCopyEmail

' Set c.c Email Addresses from form control(s).
CopyTo = Array(cc_EmailAddress, cc_EmailAddress1, cc_EmailAddress2)

' Start a session to notes.
Set Session = CreateObject("Notes.NotesSession")

' Open the mail database in notes.
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

' Create the mail document.
Set MailDoc = Maildb.CreateDocument
Call MailDoc.ReplaceItemValue("Form", "Memo")

' Set the recipient.
Call MailDoc.ReplaceItemValue("SendTo", EmailTo)

' Set the c.c. recipient(s).
Call MailDoc.ReplaceItemValue("CopyTo", CopyTo)

' Set subject.
Call MailDoc.ReplaceItemValue("Subject", "Issue Sheet " & Me.P_IssSheetID & " actions required.")

' Create and set the Body content.
Set Body = MailDoc.CREATERICHTEXTITEM("Body")
Call Body.APPENDTEXT("Issue Sheet No " & Me.P_IssSheetID & " is available for your actions. Please view the Issue sheet and forward related drawing(s) to customer for info. For your info the change(s) requested are '" & Me.ChangeGen & "'")

' Call Body.ADDNEWLINE(2)
' Call Body.EMBEDOBJECT(1454, "", "C:\filename", "Attachment")

' Example to save the message (optional).
MailDoc.SaveMessageOnSend = True

' Send the document.
Call MailDoc.ReplaceItemValue("PostedDate", Now())

' Gets the mail to appear in the Sent items folder.
Call MailDoc.Send(False)

' Clean Up.
Set Maildb = Nothing
Set MailDoc = Nothing
Set Subject = Nothing
Set Body = Nothing
Set Session = Nothing

' Confirmation messages.
MsgBox "Message has been transferred to Notes and sent."
MsgBox "Check Lotus Notes inbox to ensure no delivery failure."
End Sub

Many thanks in anticipation of some info to help resolve this issue.

Cheers,
Steve.
:banghead::banghead::banghead:
 

Users who are viewing this thread

Top Bottom