I'm trying to send email through SMTP in VBA, but is returning error.
Dim CDOmsg As CDO.Message
Set CDOmsg = New CDO.Message
With CDOmsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "myemail#gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypass"
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Update
End With
' build email parts
With CDOmsg
.Subject = "the email subject"
.From = "myemail#gmail.com"
.To = "mailto#gmail.com"
.CC = ""
.BCC = ""
.TextBody = "the full message body goes here. you may want to create a variable to hold the text"
End With
CDOmsg.Send
Set CDOmsg = Nothing
The error is on CDOmsg.Send. I've tried to send with Gmail and Yahoo Mail, but I get this same error.
Error code: -2147220973(80040213)
Error description: The transport failed to connect to the server
You can try the following but don't forget to tick the checkbox for 'Microsoft CDO for Windows 2000 Library'
Function email(ByVal sender_email As String, _
ByVal email_message As String, _
ByVal email_message2 As String, _
ByVal reply_address As String, _
ByVal sender_name As String)
Dim Mail As New Message
Dim Cfg As Configuration
Set Cfg = Mail.Configuration
'SETUP MAIL CONFIGURATION FIELDS
Cfg(cdoSendUsingMethod) = cdoSendUsingPort
Cfg(cdoSMTPServer) = 'SMTP
Cfg(cdoSMTPServerPort) = 'SMTPport
Cfg(cdoSMTPAuthenticate) = cdoBasic
Cfg(cdoSMTPUseSSL) = True
Cfg(cdoSendUserName) = 'sender_email
Cfg(cdoSendPassword) = 'password
Cfg.Fields.Update
'SEND EMAIL
With Mail
.From = 'sender_name & sender_email
.ReplyTo = 'reply_address
.To = 'receiver
.CC = 'carbonCopy
.BCC = 'blindCopy
.Subject = 'SubjectLine
.HTMLBody = 'email_message & email_message2
.Attachments.Add attFilePath
.Send
End With
Related
I am trying to add an attachment functionality to my emails. My email code is working however the attachments are being sent as ATT00001.bin files.
The variable Forms![frmMain]!TabCtl54.Pages("page56").Controls("subtblcontent").Form![attachmentlnk] is a textbox on a form which is where I would put my file name.
attachmentlnkvar = "file:///C:/Users/desktopname/Desktop/" & Forms![frmMain]!TabCtl54.Pages("page56").Controls("subtblcontent").Form![attachmentlnk] & ".pdf"
With cdomsg
.To = emailstr
.FROM = fromemailstr
.subject = Forms!frmMain.txtSubject
.Attachments.Add attachmentlnkvar
.HTMLBody = strHTML
.Send
End With
Set cdomsg = Nothing
Is there a way I can send my files as pdfs?
I am happy to share with you the function which I use to sent all my emails:
Public Sub SendMessage(Optional SubjectText = "", Optional BodyText = "", Optional AttachmentPath = "", Optional sendTo = "", Optional sendCC = "", Optional DeliveryConfirmation = True, Optional DisplayDoNotAutoSend = True, Optional SendHighPriority = True, Optional UseHTML = True)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim MultipleAttachmentPath As String
Dim CurrentAttachment As Variant
Dim aAtachments() As String
On Error GoTo ErrorMsgs
DoCmd.Hourglass True
' Create the Outlook session.
Set objOutlook = New Outlook.Application
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
If UseHTML Then
.BodyFormat = olFormatHTML
End If
If Not isnull(sendTo) And InStr(sendTo, "#") > 0 Then
.To = sendTo
End If
If Not isnull(sendCC) And InStr(sendCC, "#") > 0 Then
.CC = sendCC
End If
.Subject = SubjectText
If UseHTML Then
.HTMLBody = "<div style='font-family:Calibri,sans-serif'>" & BodyText & GetThankYouSignature & "</div>"
Else
.Body = BodyText & vbCrLf & GetUserFullNameInASCIIText & vbCrLf & vbCrLf
End If
If SendHighPriority Then
.Importance = olImportanceHigh 'High importance
End If
If DeliveryConfirmation Then
.OriginatorDeliveryReportRequested = True
.ReadReceiptRequested = True
End If
On Error Resume Next
If AttachmentPath <> "" Then
' Add attachments to the message.
If Not IsMissing(AttachmentPath) And InStr(AttachmentPath, ";") = 0 Then
Set objOutlookAttach = .Attachments.add(AttachmentPath)
ElseIf Not IsMissing(AttachmentPath) And InStr(AttachmentPath, ";") > 0 Then
aAtachments = Split(AttachmentPath, ";")
For Each CurrentAttachment In aAtachments
.Attachments.add (CurrentAttachment)
Next
End If
End If
On Error GoTo ErrorMsgs
End With
If DisplayDoNotAutoSend Or isnull(sendTo) Then
objOutlookMsg.Display
Else
objOutlookMsg.Send
End If
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
DoCmd.Hourglass False
Exit Sub
ErrorMsgs:
DoCmd.Hourglass False
If Err.Number = "287" Then
MsgBox "You clicked No to the Outlook security warning. " & _
"Rerun the procedure and click Yes to access e-mail" & _
"addresses to send your message. For more information," & _
"see the document at http://www.microsoft.com/office" & _
"/previous/outlook/downloads/security.asp. "
Else
Call LogError(Err.Number, Err.Description, "SystemUtilities", "SendMessage")
Resume Next
Resume
End If
End Sub
The variable AttachmentPath can contain multiple paths to attachments delimited by ";"
Don't use file:// etc., just the path. And backslashes.
attachmentlnkvar = "C:\Users\desktopname\Desktop\" & Forms![frmMain]!TabCtl54.Pages("page56").Controls("subtblcontent").Form![attachmentlnk] & ".pdf"
Instead of .Attachments.Add attachmentlnkvar have you tried .AddAttachment attachmentlnkvar? That's what I use to send PDF reports via an SMTP server instead of Outlook.
The problem is with your SMTP server. Try putting the attachment after the body to avoid this problem. If that doesn't work, try sending the message as plain text instead of HTML using:
.TextBody = bodyText
EXAMPLE:
attachmentlnkvar = "C:/Users/desktopname/Desktop/" & Forms![frmMain]!TabCtl54.Pages("page56").Controls("subtblcontent").Form![attachmentlnk] & ".pdf"
With cdomsg
.To = emailstr
.FROM = fromemailstr
.Subject = Forms!frmMain.txtSubject
.HTMLBody = strHTML
.AddAttachment attachmentlnkvar
.Send
End With
Set cdomsg = Nothing
EXPLANATION:
https://kb.mit.edu/confluence/pages/viewpage.action?pageId=4981187
I am trying to send an email of a file from my VB code. I have a linked table that has email addresses in it, but I am getting the run time error '-2147467259 (80004005)' We Need to Know Who to Send this to. Make sure you enter atleast one name'
Public Function sendmail(mailSub As String, mailTo As String, _
Optional msgBody As String, Optional mailCC As String, _
Optional mailBCC As String, Optional mailFrom As String, _
Optional pathToAttach As String) As Boolean
Dim oApp As Object, oMail As Object, oAttach As Object
sendmail = False
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0) 'olMailItem=0
Set oAttach = oMail.Attachments
With oMail
.BodyFormat = 2 'olFormatHTML=2, olFormatPlain=1, olFormatRichText=3
.SentOnBehalfOfName = mailFrom
.To = mailTo
.CC = mailCC
.BCC = mailBCC
.Subject = mailSub
.htmlBody = msgBody & "<BR>" & .htmlBody
.Recipients.ResolveAll
End With
If pathToAttach & "" <> "" Then oAttach.Add pathToAttach, olByValue, 1
oMail.Send '<<This is where I am getting the error
oMail.Display
sendmail = True
Exit Function
End Function
Public Function getEmails(Address_type As String) As String
Dim rst As Recordset, tbl_Email As String
tbl_Email = "tbl_Email" ' Change this as needed
On Error GoTo no_rec
Set rst = CurrentDb.OpenRecordset("SELECT * FROM " & tbl_Email & " WHERE " & _
Address_type & "=TRUE")
rst.MoveLast
rst.MoveFirst
While Not rst.EOF
getEmails = getEmails & rst![Email] & ";"
rst.MoveNext
Wend
no_rec:
If Not rst Is Nothing Then rst.Close
Set rst = Nothing
End Function
Firstly, there is no reason to call both Send and Display: if you are displaying the message, you should not call Send - the user will click the Send button.
If you replace the call to Send with Save, do you see the recipients in the message shown to the user?
I'm using vba to send email using CDO (See below) it keeps pulling a old image from over 30 days ago for the email that it is sending out. Can anyone help?
Public Function sndmail(ByVal RecipientList As String, _
ByVal Subject As String, ByVal body As String, Optional ByVal Attachment As String, _
Optional ByVal cc As String)
Dim iMsg As Message
Dim iConf As Configuration
Dim strbody As String
Dim Flds As Variant
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP.xx.xyz.COM"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
.Update
End With
With iMsg
Set .Configuration = iConf
.To = RecipientList
.cc = cc
.From = "chris#yoohoo.com"
.Subject = Subject
.HTMLBody = body
End With
iMsg.Send
End Function
...
imgfile = "C:\TEMP\FDW_Img.png"
imgfile2 = "C:\TEMP\FDW_DoD.png"
Set pp = New PowerPoint.Application
Set ppt = pp.Presentations.Open("C:\TEMP\bpp.pptx")
wbk1.Sheets("Summary by Modcode").Range("F22:Z28").Copy
ppt.Slides(1).Shapes.PasteSpecial (ppPasteBitmap)
ppt.Slides(1).Shapes(1).Export imgfile, ppShapeFormatPNG
ppt.Close
pp.Quit
DoEvents
'list of recipients
sndto = ""
'subject line for email
subj = "5 State Capital Finance Reports for " & Date
'body of email
bod = "Happy " & WeekdayName(Weekday(Date)) & "! <br>" & WeekdayName(Weekday(Date)) & "'s reports have been updated and can be found at the below links and snapshots can be found at the first weblink:<br><br>" & _
"<a href = a weblink here that currently works fine> Finance Website </a> <br>" & _
"<a href = another one here... works fine> Open vs Actuals </a> <br>" & _
"<a href = another one here... works fine> EE Report <a><br>" & _
"<a href = another one here... works fine> FDW Actuals <a>" & _
" <br> <br><img src='C:\Temp\FDW_img.png'><br><br>" & sig
'function to send email
sndmail sndto, subj, bod
Application.CutCopyMode = False
wbk1.Close False
This line is where it adds the image to the body of the email and it is adding an old image... the strange thing is that on the host pc if I pull up my email it shows correctly but on all other recipients or if I pull up my email on another pc it shows up with the old image.
" <br> <br><img src='C:\Temp\FDW_img.png'><br><br>" & sig
I'm trying to set up an .xlsm workbook to send emails to different email addresses with specific data from the spreadsheet.
I want that it doesn't matter what email client or server is used.
I'm currently trying to get it working for hotmail.
Here's my code:
Sub Button1_Click()
Dim CDO_Mail As Object
Dim CDO_Config As Object
Dim SMTP_Config As Variant
Dim strSubject As String
Dim strFrom As String
Dim strTo As String
Dim strCc As String
Dim strBcc As String
Dim strBody As String
strSubject = "SUBJECT"
strFrom = "******#hotmail.com"
strTo = "************#hotmail.com"
strCc = ""
strBcc = ""
strBody = "BODY TEXT HERE"
Set CDO_Mail = CreateObject("CDO.Message")
Set CDO_Config = CreateObject("CDO.Configuration")
CDO_Config.Load -1
Set SMTP_Config = CDO_Config.Fields
With SMTP_Config
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.live.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "******#hotmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Update
End With
With CDO_Mail
Set .Configuration = CDO_Config
End With
CDO_Mail.Subject = strSubject
CDO_Mail.From = strFrom
CDO_Mail.To = strTo
CDO_Mail.TextBody = strBody
CDO_Mail.CC = strCc
CDO_Mail.BCC = strBcc
CDO_Mail.Send
MsgBox ("Emails have been sent.")
End Sub
I get the following error:
Run-time error '-2147220975 (80040211)'
The message could not be sent to the SMTP server, The transport error code was 0x80040217. The server response was not available.
I've also tried changing the port from 25 to 587 and I get the error:
The transport failed to connect to the server.
I also initially didn't have the 2 following lines in there:
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
And when they weren't there I got the error:
The server rejected the sender address. The server response was: 530 5.7.0 Must issue a STARTTLS command first.
This script run correctly for send email SQL query result, but I need script to stop send email if the SQL query result is empty.
'Declare Constants
Const CDO_SCHEMA = "http://schemas.microsoft.com/cdo/configuration/"
Const CDO_MAIL_HEADER = "urn:schemas:mailheader:"
'Method used to send mail
Const CDO_SEND_USING_REMOTE = 2 'Send using Remote SMTP Server
'Security method used on remote SMTP server
Const CDO_ANONYMOUS = 0 'Use no authentication
Const CDO_BASIC = 1 'Use the basic (clear text) authentication
Const CDO_NTLM = 2 'Use the NTLM authentication
'Delivery Status Notifications
Const cdoDSNDefault = 0 'No DSN commands are issued
Const cdoDSNNever = 1 'No DSN commands are issued
Const cdoDSNFailure = 2 'Return a DSN if delivery fails
Const cdoDSNSuccess = 4 'Return a DSN if delivery succeeds
Const cdoDSNDelay = 8 'Return a DSN if delivery is delayed
Const cdoDSNSuccessFailOrDelay = 14 'Return a DSN if delivery succeeds, fails, or is delayed
'Set method of sending
strSendMethod = CDO_SEND_USING_REMOTE
'Remote SMTP Server Settings
strSmtpServer = "smtp.abc.com" 'Name or IP of SMTP Server
intSmtpPort = 25 'SMTP Server Port; typically 25
intSmtpTimeout = 60 'Number of seconds to try establishing a connection to the SMTP Server
strAuthenticationMethod = CDO_ANONYMOUS
'SMTP Server Authentication - IF BASIC or NTLM; NOT needed for ANONYMOUS
strUserName = ""
strPassword = ""
strUserSSL = False 'True if SMTP Server uses SSL; False if Not
'Message Settings
strTo = "asdf#abc.com"
'Separate multiple addresses with a semi-colon (;)
strCC = ""
strBCC = ""
strFrom = "no-reply-SalesInfo#abc.com"
strSubject = "Pending Sales Order - Perlu di follow up"
strBodyType = "TEXT"
strAttachment = "D:\File.txt" 'Attachment Path i.e. C:\Temp\File.txt
strDSNotification = cdoDSNDefault 'Delivery Status Option Change as needed
'WScript.Echo "Connecting to database..."
'Connect to database & select all from Table
Set objDB = DBConnect()
Set oRS = objDB.Execute("SELECT S_ORDER 'SO# ',CUSTOMER_NAME'CUSTOMER ',DATE 'Tanggal ',USERID 'INTERNAL ',CALLING 'Approval from ',LIMIT 'LIMIT ',TERM 'TERM ' from abc")
'Dump Records from Table
strOutput = "Please Check This Report :" & vbCrLf
nRec = 1
Do While Not oRS.EOF
strOutput = strOutput & "----- " & nRec & " -----" & vbCrLf
nRec = nRec + 1
For Each oFld In oRS.Fields
strOutput = strOutput & oFld.Name & " = " & oFld.Value & vbCrLf
Next
oRS.MoveNext
Loop
SendEmail strOutput
'WScript.Echo "Script Finished"
'This function sets up DB Connection using specified DSN
Function DBConnect
Set objDB = CreateObject("ADODB.Connection")
objDB.Open "DSN=SQL;uid=sa;pwd=12345"
'Set Conn = Server.CreateObject("ADODB.Connection")
'Conn.open "SQL","sa","12345"
Set DBConnect = objDB
End Function
Sub SendEmail(strBody)
'Create Objects
Set objConfig = CreateObject("CDO.Configuration")
Set objEmail = CreateObject("CDO.Message")
'Prepare email configuration
With objConfig.Fields
.Item(CDO_SCHEMA & "sendusing") = strSendMethod
.Item(CDO_SCHEMA & "smtpserver") = strSmtpServer
.Item(CDO_SCHEMA & "smtpserverport") = intSmtpPort
.Item(CDO_SCHEMA & "smtpconnectiontimeout") = intSmtpTimeout
.Item(CDO_SCHEMA & "smtpauthenticate") = strAuthenticationMethod
If.Item(CDO_SCHEMA & "smtpauthenticate") <> 0 Then
.Item(CDO_SCHEMA & "sendusername") = strUsername
.Item(CDO_SCHEMA & "sendpassword") = strPassword
.Item(CDO_SCHEMA & "smtpusessl") = strUserSSL
End If
.Update
End With
'Create email and send
With objEmail
Set.Configuration = objConfig
.To = strTo
If strCC <> "" Then
.CC = strCC
End If
If strBCC <> "" Then
.BCC = strBCC
End If
.From = strFrom
.Subject = strSubject
If strBodyType = "HTML" Then
.HTMLBody = strBody
ElseIf strBodyType = "TEXT" Then
.TextBody = strBody
End If
If strAttachment <> "" Then
.AddAttachment strAttachment
End If
If strDSNotification <> 0 And strDSNotification <> 1 Then
.Fields(CDO_MAIL_HEADER & "disposition-notification-to") = strFrom
.Fields(CDO_MAIL_HEADER & "return-receipt-to") = strFrom
.DSNOptions = strDSNotification
.Fields.update
End If
.Send
End With
End Sub
Simply make sending email depend on whether your query returned records or not.
Change this line:
SendEmail strOutput
into this:
If nRec > 1 Then SendEmail strOutput
by putting the following condition
if oRS.RecordCount>0 or oRS is Not Nothing then
you will be able to control the email sending.
try the following:
Const CDO_SCHEMA = "http://schemas.microsoft.com/cdo/configuration/"
Const CDO_MAIL_HEADER = "urn:schemas:mailheader:"
'Method used to send mail
Const CDO_SEND_USING_REMOTE = 2 'Send using Remote SMTP Server
'Security method used on remote SMTP server
Const CDO_ANONYMOUS = 0 'Use no authentication
Const CDO_BASIC = 1 'Use the basic (clear text) authentication
Const CDO_NTLM = 2 'Use the NTLM authentication
'Delivery Status Notifications
Const cdoDSNDefault = 0 'No DSN commands are issued
Const cdoDSNNever = 1 'No DSN commands are issued
Const cdoDSNFailure = 2 'Return a DSN if delivery fails
Const cdoDSNSuccess = 4 'Return a DSN if delivery succeeds
Const cdoDSNDelay = 8 'Return a DSN if delivery is delayed
Const cdoDSNSuccessFailOrDelay = 14 'Return a DSN if delivery succeeds, fails, or is delayed
'Set method of sending
strSendMethod = CDO_SEND_USING_REMOTE
'Remote SMTP Server Settings
strSmtpServer = "smtp.abc.com" 'Name or IP of SMTP Server
intSmtpPort = 25 'SMTP Server Port; typically 25
intSmtpTimeout = 60 'Number of seconds to try establishing a connection to the SMTP Server
strAuthenticationMethod = CDO_ANONYMOUS
'SMTP Server Authentication - IF BASIC or NTLM; NOT needed for ANONYMOUS
strUserName = ""
strPassword = ""
strUserSSL = False 'True if SMTP Server uses SSL; False if Not
'Message Settings
strTo = "asdf#abc.com"
'Separate multiple addresses with a semi-colon (;)
strCC = ""
strBCC = ""
strFrom = "no-reply-SalesInfo#abc.com"
strSubject = "Pending Sales Order - Perlu di follow up"
strBodyType = "TEXT"
strAttachment = "D:\File.txt" 'Attachment Path i.e. C:\Temp\File.txt
strDSNotification = cdoDSNDefault 'Delivery Status Option Change as needed
'WScript.Echo "Connecting to database..."
'Connect to database & select all from Table
Set objDB = DBConnect()
Set oRS = objDB.Execute("SELECT S_ORDER 'SO# ',CUSTOMER_NAME'CUSTOMER ',DATE 'Tanggal ',USERID 'INTERNAL ',CALLING 'Approval from ',LIMIT 'LIMIT ',TERM 'TERM ' from abc")
if oRS.RecordCount>0 or oRS is Not Nothing then
'Dump Records from Table
strOutput = "Please Check This Report :" & vbCrLf
nRec = 1
Do While Not oRS.EOF
strOutput = strOutput & "----- " & nRec & " -----" & vbCrLf
nRec = nRec + 1
For Each oFld In oRS.Fields
strOutput = strOutput & oFld.Name & " = " & oFld.Value & vbCrLf
Next
oRS.MoveNext
Loop
SendEmail strOutput
end if
'WScript.Echo "Script Finished"
'This function sets up DB Connection using specified DSN
Function DBConnect
Set objDB = CreateObject("ADODB.Connection")
objDB.Open "DSN=SQL;uid=sa;pwd=12345"
'Set Conn = Server.CreateObject("ADODB.Connection")
'Conn.open "SQL","sa","12345"
Set DBConnect = objDB
End Function
Sub SendEmail(strBody)
'Create Objects
Set objConfig = CreateObject("CDO.Configuration")
Set objEmail = CreateObject("CDO.Message")
'Prepare email configuration
With objConfig.Fields
.Item(CDO_SCHEMA & "sendusing") = strSendMethod
.Item(CDO_SCHEMA & "smtpserver") = strSmtpServer
.Item(CDO_SCHEMA & "smtpserverport") = intSmtpPort
.Item(CDO_SCHEMA & "smtpconnectiontimeout") = intSmtpTimeout
.Item(CDO_SCHEMA & "smtpauthenticate") = strAuthenticationMethod
If.Item(CDO_SCHEMA & "smtpauthenticate") <> 0 Then
.Item(CDO_SCHEMA & "sendusername") = strUsername
.Item(CDO_SCHEMA & "sendpassword") = strPassword
.Item(CDO_SCHEMA & "smtpusessl") = strUserSSL
End If
.Update
End With
'Create email and send
With objEmail
Set.Configuration = objConfig
.To = strTo
If strCC <> "" Then
.CC = strCC
End If
If strBCC <> "" Then
.BCC = strBCC
End If
.From = strFrom
.Subject = strSubject
If strBodyType = "HTML" Then
.HTMLBody = strBody
ElseIf strBodyType = "TEXT" Then
.TextBody = strBody
End If
If strAttachment <> "" Then
.AddAttachment strAttachment
End If
If strDSNotification <> 0 And strDSNotification <> 1 Then
.Fields(CDO_MAIL_HEADER & "disposition-notification-to") = strFrom
.Fields(CDO_MAIL_HEADER & "return-receipt-to") = strFrom
.DSNOptions = strDSNotification
.Fields.update
End If
.Send
End With
End Sub