Sending email via ahk with emoji produces issues

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
zvit
Posts: 226
Joined: 07 Nov 2017, 06:15

Sending email via ahk with emoji produces issues

Post by zvit » 22 Jan 2021, 03:29

I use an ahk script to send regular emails that works fine. 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:

Code: Select all

pmsg.TextBody
to:

Code: Select all

pmsg.HtmlBody
I have an emoji in the .html file name and the subject:

Code: Select all

MailSubject = ✌️ Welcome to Vinewood Studios!
FileRead, MailBody, J:\ONLINE_STORAGE\GOOGLE_DRIVE\Gmail Templates\VSA\VSA-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:

Image

Image


I tried using the Unicode of the emoji, like this (without the colon):

Code: Select all

MailSubject = {U+1F601} "Welcome to Vinewood Studios!"
but it didn't read it at all (email subject says "no subject"):

Image

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)

Code: Select all

MailSubject := {U+1F601} "Welcome to Vinewood Studios!"

Code: Select all

MailSubject := {U+1F601} . "Welcome to Vinewood Studios!"

Code: Select all

emoji := {U+1F601}️
MailSubject := emoji . "Welcome to Vinewood Studios!"
When using :=

Code: Select all

MailSubject := ✌️ Welcome to Vinewood Studios!
The email subject just reads the number "1".

Any ideas on how to send an email with emojis and special characters?
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Sending email via ahk with emoji produces issues

Post by AHKStudent » 22 Jan 2021, 04:39

I dont know a lot about this but what happens if you do a test like this

MsgBox, % clipboard:= chr(0x1F601)

and then paste into google does it do anything?
User avatar
zvit
Posts: 226
Joined: 07 Nov 2017, 06:15

Re: Sending email via ahk with emoji produces issues

Post by zvit » 22 Jan 2021, 04:51

That works fine.

Image
User avatar
zvit
Posts: 226
Joined: 07 Nov 2017, 06:15

Re: Sending email via ahk with emoji produces issues

Post by zvit » 24 Jan 2021, 07:32

I also need to send Hebrew emails, that are coming out gibberish. Need to define iso-8859-1 somewhere? Any suggestions?

Image
User avatar
zvit
Posts: 226
Joined: 07 Nov 2017, 06:15

Re: Sending email via ahk with emoji produces issues

Post by zvit » 24 Jan 2021, 22:39

UDATE: Adding

Code: Select all

pmsg.BodyPart.Charset := "utf-8"
worked in sending the correct emoji in the subject line. Didn't work to display Hebrew chars in the email body.

Code: Select all

pmsg.HtmlBodyPart.Charset
and

Code: Select all

pmsg.TextBodyPart.Charset
or a combination of them didn't help either.
But I'm now certain that it's an issue with the ComObj and that's what I'm researching now.

p.s. the HTML file itself is already saved as utf-8
jackn11
Posts: 10
Joined: 14 Dec 2020, 17:34

Re: Sending email via ahk with emoji produces issues

Post by jackn11 » 25 Jan 2021, 00:27

I have hotkeys programmed into my script and they work fine when I just send the hex code for the keys. I'm running Windows 10 and I edited the registry so that I can enter any Unicode character with its hex code on the numpad, so this may be why it is working for me but not you. Perhaps try that registry edit. It should be simple to find online.
User avatar
zvit
Posts: 226
Joined: 07 Nov 2017, 06:15

Re: Sending email via ahk with emoji produces issues

Post by zvit » 25 Jan 2021, 01:57

I've seen a registry edit mentioned but let me ask, what do you do with your code? When you say "sending" do you mean sending an email? Because I have no problem with using an emoji or Hebrew with a regular ahk "Send" command - I don't even have to use Unicode.
jackn11
Posts: 10
Joined: 14 Dec 2020, 17:34

Re: Sending email via ahk with emoji produces issues

Post by jackn11 » 26 Jan 2021, 00:02

My exact code is

Code: Select all

:*?::thumbsup::{U+1F44D}
What this does is replace every occurrence of ":thumbsup" with the thumbs up emoji, and it works in pretty much all programs except Microsoft Word, which is notoriously terrible with AHK.
User avatar
zvit
Posts: 226
Joined: 07 Nov 2017, 06:15

Re: Sending email via ahk with emoji produces issues

Post by zvit » 26 Jan 2021, 00:11

Ok, thanks but this doesn't solve my issue because as I said, that :: code works for me too. My issue is only when sending the emoji or Hebrew via an email, that I have an issue.

This has nothing to do my issue but I also replace variables inside the HTML file with values coming from a function that works great in English only.

Code: Select all

_vYear := "{YEAR}"
_vMonth := "{MONTH}"
_vTotal := "{TOTAL}"

MailBody := StrReplace(MailBody, _vYear, _nYear)
MailBody := StrReplace(MailBody, _vMonth, _nMonth)
MailBody := StrReplace(MailBody, _vTotal, _nTotal)
Post Reply

Return to “Ask for Help (v1)”