Link to home
Start Free TrialLog in
Avatar of Tom Crowfoot
Tom CrowfootFlag for United Kingdom of Great Britain and Northern Ireland

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?

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

Open in new window

Avatar of Barry Cunney
Barry Cunney
Flag of Ireland image

Hi
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
Avatar of Tom Crowfoot

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?
This should out put the details to the debug/output window - From the View menu make sure this window is switched on
here we go ...

  : BodyString : "<div>Hello</div>

<div>&nbsp;</div>

<div><font color=red>Hello in red</font></div>" : String

  : DefaultSignatureString : "C:\Users\tcrowfoot\AppData\Roaming\Microsoft\Signatures\New Logo.rtf" : String

  : Signature : "{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff31507\deff0\stshfdbch31505\stshfloch31506\stshfhich31506\stshfbi31507\deflang2057\deflangfe2057\themelang2057\themelangfe0\themelangcs0"
ASKER CERTIFIED SOLUTION
Avatar of Barry Cunney
Barry Cunney
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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


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

Open in new window

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
Hi

Thanks for that - have just tested it & it comes out all ok
Argh, actually it doesn't (I had it sending as .HTMLbody as I was trying a few other solutions)

When sending just the body of the email as an RTF the attachment is in the main body of the email rather than in the attachments
User generated image
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