I use an ahk script to send regular emails that works fine (will post the entire script at end of question). I am now setting up a script that will send HTML formatted emails. The only change you need to make to send HTML formatted emails is changing:
pmsg.TextBody
to:
pmsg.HtmlBody
I have an emoji in the .html file name and the subject:
MailSubject = ?? Welcome to Vinewood Studios!
FileRead, MailBody, J:ONLINE_STORAGEGOOGLE_DRIVEGmail TemplatesVSAVSA-PRE-ORDER?? Welcome to Vinewood Studios!.html
The script reads the html file fine and sends the email. The issue is that wherever there is an emoji or special character, e,g, ? or ?, it produces question marks or symbols. Check out the subject line and footer here:
I tried using the Unicode of the emoji, like this (without the colon):
MailSubject = {U+1F601} "Welcome to Vinewood Studios!"
but it didn't read it at all (email subject says "no subject"):
All of these ways won't even send, I get an error about "Missing "key" in object literal.:
(I understand WHY I get an error, because {U+1F601} is not being seen as a "value" but rather a string. However, this is how it's used when you want to replace text with an emoji so I don't know why it would be different in this case)
MailSubject := {U+1F601} "Welcome to Vinewood Studios!"
MailSubject := {U+1F601} . "Welcome to Vinewood Studios!"
emoji := {U+1F601}?
MailSubject := emoji . "Welcome to Vinewood Studios!"
When using :=
MailSubject := ?? Welcome to Vinewood Studios!
The email subject just reads the number "1".
When testing a simple msgbox with the Unicode of the emoji and pasting to Google, it works fine:
I also can't send Hebrew HTML files, comes out Gibrrish:
Any ideas on how to send an email with emojis and special characters?
UPDATE: adding pmsg.BodyPart.Charset := "utf-8" solved the issue in sending the correct emoji in the subject line. Didn't work to display Hebrew chars in the email body.
Here's the script:
MailSubject := ?? Welcome to Vinewood Studios!
FileRead, MailBody, J:ONLINE_STORAGEGOOGLE_DRIVEGmail TemplatesVSAVSA-PRE-ORDER?? Welcome to Vinewood Studios!.html
SendEmail(MailBody, MailSubject)
SendEmail(MailBody, MailSubject, SendTo:="ztwersky@gmail.com")
{
pmsg := ComObjCreate("CDO.Message")
pmsg.From := """VSA Management"" <support@vinewoodstudios.com>"
pmsg.To := SendTo
pmsg.BCC := "" ; Blind Carbon Copy, Invisable for all, same syntax as CC
pmsg.CC := ""
pmsg.Subject := MailSubject
pmsg.HtmlBody := MailBody
pmsg.BodyPart.Charset := "utf-8" ;Displays emoji correctly in subject only
;sAttach := ; "Path_Of_Attachment" ; can add multiple attachments
; the delimiter is |
fields := Object()
fields.smtpserver := "smtp.gmail.com" ; specify your SMTP server
fields.smtpserverport := 465 ; 25
fields.smtpusessl := True ; False
fields.sendusing := 2 ; cdoSendUsingPort
fields.smtpauthenticate := 1 ; cdoBasic
fields.sendusername := "ztwersky@gmail.com"
fields.sendpassword := "PASSWORD"
fields.smtpconnectiontimeout := 60
schema := "http://schemas.microsoft.com/cdo/configuration/"
pfld := pmsg.Configuration.Fields
For field,value in fields
pfld.Item(schema . field) := value
pfld.Update()
Loop, Parse, sAttach, |, %A_Space%%A_Tab%
pmsg.AddAttachment(A_LoopField)
pmsg.Send()
msgbox, Email sent.
}
question from:
https://stackoverflow.com/questions/65869757/sending-email-via-ahk-with-emoji-produces-issues