Format Email Body (1 Viewer)

Momma

Member
Local time
Today, 20:46
Joined
Jan 22, 2022
Messages
119
Hi everyone
I'm sending emails using the attached code. I want to format the strBody to a certain font and size.
I do appreciate any help
Thanks


Code:
                Set FD = Application.FileDialog(msoFileDialogFilePicker)
                With FD
                    .InitialFileName = "c:\"
                        Set OutMail = OutApp.CreateItem(0)
                        strBody = "Dear " & Forms!frmcontactgrouplistbox!ContactList.Column(7, i) & "<br><br>" & ReadTextFile(strText)
                        With OutMail
                            'create the email
                            
                            .To = Forms!frmcontactgrouplistbox!ContactList.Column(9, i)
                            .Subject = "Sale Guarantee & Health Declaration"
                            .HTMLBody = strBody & "<IMG src=z:\EmailFiles\Logo.png><br>"
                
                            'add the reports
                            .Attachments.Add NewFilePath & Filename1
                            .Attachments.Add NewFilePath & Filename2
                            .Attachments.Add NewFilePath & Filename3
 
                            'send the email
                            .Display
                        End With
                End With
 
Gotta learn some HTML and CSS.


The specific css element you want to look at is font:


My advice is to create a new email message in whatever email software you use (outlook, thunderbird, etc.), format it like you want it to look and then you should be able to view the HTML source of that email, copy it and then use it in your VBA to have it generate the email you want.
 
Thanks for the advice.
I have tried this but it only changes the font and the size for the first part of the body, which is "Dear ...."
It does not include the Logo.png at the end of the email.

Code:
                Set FD = Application.FileDialog(msoFileDialogFilePicker)
                With FD
                    .InitialFileName = "c:\"
                        Set OutMail = OutApp.CreateItem(0)
                        strBody = "Dear " & Forms!frmcontactgrouplistbox!ContactList.Column(7, i) & "<br><br>" & ReadTextFile(strText)
                        With OutMail
                            'create the email
                            
                            .To = Forms!frmcontactgrouplistbox!ContactList.Column(9, i)
                            .Subject = "Sale Guarantee & Health Declaration"
                            .HTMLBody = "<HTML><BODY style=font-family:Calibri; style=font-size:18px>" & strBody & "<IMG src=z:\EmailFiles\Logo.png><br>"
                            
                            'add the reports
                            .Attachments.Add NewFilePath & Filename1
                            .Attachments.Add NewFilePath & Filename2
                            .Attachments.Add NewFilePath & Filename3
 
                            'send the email
                            .Display
                        End With
                End With
 
An image is an image, you can only change its font by editing the image--e.g. in photoshop
 
Hi everyone
I'm sending emails using the attached code. I want to format the strBody to a certain font and size.
I do appreciate any help
Thanks

Code:
                Set FD = Application.FileDialog(msoFileDialogFilePicker)
                With FD
                    .InitialFileName = "c:\"
                        Set OutMail = OutApp.CreateItem(0)
                        strBody = "Dear " & Forms!frmcontactgrouplistbox!ContactList.Column(7, i) & "<br><br>" & ReadTextFile(strText)
                        With OutMail
                            'create the email
                         
                            .To = Forms!frmcontactgrouplistbox!ContactList.Column(9, i)
                            .Subject = "Sale Guarantee & Health Declaration"
                            .HTMLBody = strBody & "<IMG src=z:\EmailFiles\Logo.png><br>"
             
                            'add the reports
                            .Attachments.Add NewFilePath & Filename1
                            .Attachments.Add NewFilePath & Filename2
                            .Attachments.Add NewFilePath & Filename3
 
                            'send the email
                            .Display
                        End With
                End With
You shoudn't link an image from your local/shared disc, the image must be accessible from the internet.

If you want to embed the image into the mail body, you have to search information about "AddRelatedBodyPart"
Code:
            Set Attachment = Message.AddRelatedBodyPart(CurrentDBDir() & imageName2, imageName2, cdoRefTypeId)
            Attachment.Fields.Item("urn:schemas:mailheader:Content-ID") = "<imageId2>"                   ' set an ID we can refer to in HTML
 
Last edited:

Users who are viewing this thread

Back
Top Bottom