Tom Crowfoot
asked on
Access to send Emails
Dear Experts
I am building a mailshot database using Access - this will allow users to send a personalised mailshot (Dear John, Dear Paul etc.) with an attachment & with an RTF signature block (really keen not to use am HTML one as the pictures never seem to come out)
I haven't started on the personalisation piece (which will be a simple rst) but have managed to add the signature block & attachment to the email. However I cannot add the content of the email (which comes from a Rich Text formatted field [email_body].
I think the adding of the RTF signature block somehow clashes with the formatting of [email_body] so that bit doesn't get added.
Below is the code I am using - can anyone help?
I am building a mailshot database using Access - this will allow users to send a personalised mailshot (Dear John, Dear Paul etc.) with an attachment & with an RTF signature block (really keen not to use am HTML one as the pictures never seem to come out)
I haven't started on the personalisation piece (which will be a simple rst) but have managed to add the signature block & attachment to the email. However I cannot add the content of the email (which comes from a Rich Text formatted field [email_body].
I think the adding of the RTF signature block somehow clashes with the formatting of [email_body] so that bit doesn't get added.
Below is the code I am using - can anyone help?
Private Sub SendMail_Click()
'
Dim OutApp As Object
Dim OutMail As Object
' create content Strings
Dim BodyString As String
Dim DefaultSignatureString As String
Dim Signature As String
Dim AttachmentString As String
Dim SubjectLine As String
SubjectLine = Me.Subject_Line
AttachmentString = Me.Attachment
BodyString = Me.Email_Body
DefaultSignatureString = Me.Email_Signature
If Dir(DefaultSignatureString) <> "" Then
Signature = GetBoiler(DefaultSignatureString)
Else
Signature = ""
End If
'Create Outlook Session
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "info@digbyedwards.com"
.CC = ""
.BCC = ""
.Subject = SubjectLine
.RTFBody = BodyString & "<br>" & Signature
.Attachments.Add AttachmentString
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
ASKER
Hi,
I've put in the code Debug.Print BodyString & "<br>" & Signature , but sadly I have no idea how to see what the result of that is - what do I do?
I've put in the code Debug.Print BodyString & "<br>" & Signature , but sadly I have no idea how to see what the result of that is - what do I do?
This should out put the details to the debug/output window - From the View menu make sure this window is switched on
ASKER
here we go ...
: BodyString : "<div>Hello</div>
<div> </div>
<div><font color=red>Hello in red</font></div>" : String
: DefaultSignatureString : "C:\Users\tcrowfoot\AppDat a\Roaming\ Microsoft\ Signatures \New Logo.rtf" : String
: Signature : "{\rtf1\adeflang1025\ansi\ ansicpg125 2\uc1\adef f31507\def f0\stshfdb ch31505\st shfloch315 06\stshfhi ch31506\st shfbi31507 \deflang20 57\deflang fe2057\the melang2057 \themelang fe0\themel angcs0"
: BodyString : "<div>Hello</div>
<div> </div>
<div><font color=red>Hello in red</font></div>" : String
: DefaultSignatureString : "C:\Users\tcrowfoot\AppDat
: Signature : "{\rtf1\adeflang1025\ansi\
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi
Thanks for that, the GetBoiler function code is below, I'm not 100% certain what it does, was taken from this question: https://www.experts-exchange.com/questions/28226876/Access-to-send-Emails-with-Outlook-signature-block.html
Thanks for that, the GetBoiler function code is below, I'm not 100% certain what it does, was taken from this question: https://www.experts-exchange.com/questions/28226876/Access-to-send-Emails-with-Outlook-signature-block.html
Function GetBoiler(ByVal sFile As String) As String
'Dick 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
As a test, please try excluding the signature and confirm if the e-mail body gets created and formatted OK
Change the line
.RTFBody = BodyString & "<br>" & Signature
to
.RTFBody = BodyString
Change the line
.RTFBody = BodyString & "<br>" & Signature
to
.RTFBody = BodyString
ASKER
Hi
Thanks for that - have just tested it & it comes out all ok
Thanks for that - have just tested it & it comes out all ok
ASKER
ASKER
Thanks for your help on this one - the closing "}" was the offending item - there didn't seem to be a way of adding that in in a consistent manner across all user's signature blocks, so have adapted the Db so users copy & paste their signature block into the main body of the email
Please do a Debug.Print of BodyString & "<br>" & Signature and post it up so as we can see the content of this - it may be a case that there is a missing closing tag or something like that