Hi All,
I'm using the below code to send email from outlook. Every thing is working fine except it fails to send the mail.
The .send step is executing without any error but email is not sent. The .Display step is also executing fine and I
see the mail is created the way I want with CC,Subject,Body and Signature but the .send is not working.
Tried using .SendMail and .Sendkeys "%s" but no luck. Using Outlook 2013. And yes we need to select Classification before sending the mail
which is my compony's internal property. The classification window pops up when we hit the send button. but when I try to do it through code
the .send does not do what it suppose to do.
VBA Code
=======
Sub Mail_Outlook_With_Signature_Html_2()
' Don't forget to copy the function GetBoiler in the module.
' Working in Office 2000-2016
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SigString As String
Dim Signature As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "<H3><B>Dear Customer Ron de Bruin</B></H3>" & _
"Please visit this website to download the new version.<br>" & _
"Let me know if you have problems.<br>" & _
"<A HREF=""http://www.rondebruin.nl/tips.htm"">Ron's Excel Page</A>" & _
"<br><br><B>Thank you</B>"
'Change only Mysig.htm to the name of your signature
SigString = Environ("appdata") & _
"\Microsoft\Signatures\hemant.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
On Error Resume Next
With OutMail
.To = "abc@xyz.com"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.HTMLBody = strbody & "<br>" & Signature
.Display
.OlSensitivity = olConfidential
' .Save
.Send 'or use .Display
.SendKeys "%s"
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
-----------------------------------------------------------------------------
Function GetBoiler(ByVal sFile As String) As String
'**** Kusleika
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function
-------------------------------------------------------------------------------
Thanks in Advance....
I'm using the below code to send email from outlook. Every thing is working fine except it fails to send the mail.
The .send step is executing without any error but email is not sent. The .Display step is also executing fine and I
see the mail is created the way I want with CC,Subject,Body and Signature but the .send is not working.
Tried using .SendMail and .Sendkeys "%s" but no luck. Using Outlook 2013. And yes we need to select Classification before sending the mail
which is my compony's internal property. The classification window pops up when we hit the send button. but when I try to do it through code
the .send does not do what it suppose to do.
VBA Code
=======
Sub Mail_Outlook_With_Signature_Html_2()
' Don't forget to copy the function GetBoiler in the module.
' Working in Office 2000-2016
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SigString As String
Dim Signature As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "<H3><B>Dear Customer Ron de Bruin</B></H3>" & _
"Please visit this website to download the new version.<br>" & _
"Let me know if you have problems.<br>" & _
"<A HREF=""http://www.rondebruin.nl/tips.htm"">Ron's Excel Page</A>" & _
"<br><br><B>Thank you</B>"
'Change only Mysig.htm to the name of your signature
SigString = Environ("appdata") & _
"\Microsoft\Signatures\hemant.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
On Error Resume Next
With OutMail
.To = "abc@xyz.com"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.HTMLBody = strbody & "<br>" & Signature
.Display
.OlSensitivity = olConfidential
' .Save
.Send 'or use .Display
.SendKeys "%s"
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
-----------------------------------------------------------------------------
Function GetBoiler(ByVal sFile As String) As String
'**** Kusleika
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function
-------------------------------------------------------------------------------
Thanks in Advance....