Sending email via ahk with emoji produces issues - html-email

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_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:
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_STORAGE\GOOGLE_DRIVE\Gmail Templates\VSA\VSA-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.
}

This is maybe not necessarily going to be a full answer, but it's too long to be a comment and there's a few issues that need to be fixed with your script.
I don't have/use a gmail SMTP server so I can't test.
So onto the problems.
Out of all your attempts to specify a string containing an emoji, this is only correct one:
MailSubject = ✌️ Welcome to Vinewood Studios!
I italicized correct, because it's legacy syntax, in modern expression syntax, it should look like this:
MailSubject := "✌️ Welcome to Vinewood Studios!"
This is going to be correct, if you save your script file with encoding that supports the Unicode character (your emoji) and run the script with an Unicode AHK version (you should be fine on these fronts though, since you managed to get an AHK messagebox to display that emoji character).
Here's what wrong with your incorrect attempts:
MailSubject = {U+1F601} "Welcome to Vinewood Studios!"
Still in legacy syntax. All of that is going to be interpreted as a literal string. AHK sees nothing special in this string.
MailSubject := {U+1F601} "Welcome to Vinewood Studios!"
MailSubject := {U+1F601} . "Welcome to Vinewood Studios!"
These two are equal (the concatenation operator . is optional/redundant), but they also equally wrong.
The {U+...} Unicode character notation is supposed to be treated as just a normal string, nothing more special than that. A supported AHK command when then notice it and translate it to the corresponding Unicode character.
Right now what you're trying to do is concatenate some incorrectly defined (hence your script error) object with a string.
The correct would be
MailSubject := "{U+1F601} Welcome to Vinewood Studios!"
However, as you maybe have noticed, I mentioned that only a supported AHK command would care about the {U+...} notation.
That notation is meant for send commands(docs), so it's not going to be of any help for you. Your email subject would just read the literal string {U+1F601} Welcome to Vinewood Studios!.
If you wanted to store the Unicode character in your script without typing out the Unicode character (useful so you wouldn't have to worry about retaining the correct encoding on your script file always when trying to share it or whatnot), you could use e.g Chr()(docs) like so:
MailSubject := Chr(0x1F601) " Welcome to Vinewood Studios!".
emoji := {U+1F601}️
MailSubject := emoji . "Welcome to Vinewood Studios!"
And here have the some problems as described above.
If you used emoji := "{U+1F601}️", it would be correct (except for a missing space between the emoji and the word Welcome) if used on a supported AHK command (send command).
MailSubject := ✌️ Welcome to Vinewood Studios!
Here you're in modern expression syntax (as you should be), but you're not using quotes to indicate you're specifying a string.
So what you're doing here is concatenating five empty variables (named ✌️, Welcome, to, Vinewood and Studios) together, which leaves you out with nothing, and then you're inverting that value with the logical-NOT operator !(docs).
Nothing evaluates to false, and then inverting false evaluates to true (1).
Ok, so hopefully you now might be able to understand what went wrong with your attempts.
But as said above, the MailSubject = ✌️ Welcome to Vinewood Studios! attempt should've worked? (At least ss far as I can tell, I can only assume you saved your script with a supporting encoding and ran the script with an Unicode AHK version).
More than likely what's going wrong, is that you have to specify a supporting encoding for your CDO.Message object.
A Google search for CDO.Message encoding yields quite a few results for people having this problem (e.g this or this) And there are varied solutions people are applying. Most common of which seems to be specifying a field named charset to utf-8.
I can't test the actual solution, but I hope this helps.
If you still have trouble understanding some of the AHK code, I can answer those questions.

To use Unicode, make sure your AHK files are saved with the UTF-8 BOM encoding.
Quote from Why are the non-ASCII characters in my script displaying or sending incorrectly?:
Although AutoHotkey supports Unicode text, it is optimized for backward compatibility, which means defaulting to the ANSI encoding rather than the more internationally recommended UTF-8. AutoHotkey will not automatically recognize a UTF-8 file unless it begins with a byte order mark.

Related

Pl sql convert national characters to unicode

I try to convert Danish national characters to unicode. Is there function in plsql or parameter to plsql function which can help me ? I try this select convert ('Æ, æ:,Ø, ø:,Å, å:','AL32UTF8') from dual; but it doesnt help. As a workaround I used in my code something like that
w_temp := replace('Æ, æ:,Ø, ø:,Å, å:','å','\u00E5');
w_temp := replace(w_temp,'Å','\u00C5');
w_temp := replace(w_temp,'æ','\u00E6');
w_temp := replace(w_temp,'Æ','\u00C6');
w_temp := replace(w_temp,'ø','\u00F8');
w_temp := replace(w_temp,'Ø','\u00D8');
but this method is like a monkey job. My code is not prepared for any other national characters - have you any suggestion?
The CONVERT() function can be used as follows CONVERT('fioajfiohawiofh',<ORIGIN_CHARSET>,<DESTINATION_CHARSET>).
I don't know your charset, but you can try finding useful one using this SELECT:
SELECT
CONVERT('Æ, æ:,Ø, ø:,Å, å:',cs.value,'UTF8') AS conv
,cs.value
,cs.isdeprecated
FROM
V$NLS_VALID_VALUES cs
WHERE
cs.parameter = 'CHARACTERSET'
;
I'm not sure what the big picture is, but assuming that you currently have your data in a database with a single character set that supports your diacritics, I would rather use a completely different approach:
export the needed data your database and the existing character set
recreate the database with a unicode character set
(very likely) change te definition and install all database objects with CHAR instead of BYTE semantics
import all the data into the new database
Clearly there is a lot of details to sort out, but having Oracle to properly convert the character sets during import, seems to be only reasonanble way to go.

Unix mail automatically sending my message as an attachment

I have a mail command that looks something like this:
sh ~/filter.sh ~/build/site_build.err | mail -s "Site updated." me\#site.com
The bash script has a few commands, mostly grep, to filter the stderr. It sends the filtered content to me when our build process has finished.
It used to send the file contents in the message body, however now it's sending as an attachment, which I do not want.
When I delete most of the text it sends to me in the message body once again, so I've reasoned that this has to do with the message size -- is this correct?
Anyway, how can I prevent Unix from sending the message contents as an attachment, no matter the circumstances?
Thanks!
Still unsure as many things could cause mail to apparently send input as attachement. But in many Linux distribution, mail is an alias for is heirloom mailx. It is known to encode its input if there are any non printable characters in it.
As soon as it finds non standards characters, it adds the following headers to the mail :
Content-Type: application/octet-stream
Content-Transfert-Encoding: base64
and the text of the mail is effectively base 64 encoded. It is not a true attachement, but many mail readers treat such mails as an empty body with an unnamed attached file.
If your LANG environment variable declares a locale that can use non 7 bits chars (éèûôüö ...) mail seems to be clever enough to declare an extended charset (ISO-8859-1 for fr locale) and to do quoted-printable encoding. So even with (at least west european) non 7bits ASCII characters in the message, provided there are no control chararacters, the mail should be sent normally.
The alternative would be to filter all non printable characters from the output of filter.sh, and the last chance solution would be not to use mail and directly use sendmail.
(Ref : an answer of mine to an other post but that one concerned java)

How to convert UNICODE Hebrew appears as Gibberish in VBScript?

I am gathering information from a HEBREW (WINDOWS-1255 / UTF-8 encoding) website using vbscript and WinHttp.WinHttpRequest.5.1 object.
For Example :
Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
...
'writes the file as unicode (can't use Ascii)
Set Fileout = FSO.CreateTextFile("c:\temp\myfile.xml", true, true)
....
Fileout.WriteLine(objWinHttp.responsetext)
When Viewing the file in notepad / notepad++, I see Hebrew as Gibrish / Gibberish.
For example :
äìëåú - äøá àáøäí éåñó - îåøùú
I need a vbscript function to return Hebrew correctly, the function should be similar to the following http://www.pixiesoft.com/flip/ choosing the 2nd radio button and press convert button , you will see Hebrew correctly.
Your script is correctly fetching the byte stream and saving it as-is. No problems there.
Your problem is that the local text editor doesn't know that it's supposed to read the file as cp1255, so it tries the default on your machine of cp1252. You can't save the file locally as cp1252, so that Notepad will read it correctly, because cp1252 doesn't include any Hebrew characters.
What is ultimately going to be reading the file or byte stream, that will need to pick up the Hebrew correctly? If it does not support cp1255, you will need to find an encoding that is supported by that tool, and convert the cp1255 string to that encoding. Suggest you might try UTF-8 or UTF-16LE (the encoding Windows misleadingly calls 'Unicode'.)
Converting text between encodings in VBScript/JScript can be done as a side-effect of an ADODB stream. See the example in this answer.
Thanks to Charming Bobince (that posted the answer), I am now able to see HEBREW correctly (saving a windows-1255 encoding to a txt file (notpad)) by implementing the following :
Function ConvertFromUTF8(sIn)
Dim oIn: Set oIn = CreateObject("ADODB.Stream")
oIn.Open
oIn.CharSet = "X-ANSI"
oIn.WriteText sIn
oIn.Position = 0
oIn.CharSet = "WINDOWS-1255"
ConvertFromUTF8 = oIn.ReadText
oIn.Close
End Function

Get window title with AppleScript in Unicode

I've stuck with the following problem:
I have a script which is retrieving title form the Firefox window:
tell application "Firefox"
if the (count of windows) is not 0 then
set window_name to name of front window
end if
end tell
It works well as long as the title contains only English characters but when title contains some non-ASCII characters(Cyrillic in my case) it produces some utf-8 garbage. I've analyzed this garbage a bit and it seems that my Cyrillic character is converted to the Utf-8 without any concerning about codepage i.e instead of using Cyrillic codepage for conversion it uses non codepages at all and I have utf-8 text with characters different from those in the window title.
My question is: How can I retrieved the window title in utf-8 directly without any conversion?
I can achieve this goal by using AXAPI but I want to achieve this by AppleScript because AXAPI needs some option turned on in the system.
UPD:
It works fine in the AppleScript Editor. But I'm compiling it through the C++ code via OSACompile->OSAExecute->OSADisplay
I don't know the guts of the AppleScript Editor so maybe it has some inside information about how to encode the characters
I've found the answer when wrote update. Sometimes it is good to ask a question for better it understanding :)
So for the future searchers: If you want to use unicode result of the script execution you should provide typeUnicodeText to the OSADisplay then you will have result in the UTF-16LE in the result AEDesc

Using Utl_mail package to send email on Oracle 10g grid

Can somebody please advice using special character in message body is allowed or not? I am using a word "month's" in the nessage body but it is getting replaced by "month?s" in the email. Please HELP!!!!
Don't use MS Word to edit your code :)
Most probably, your editor is replacing the ' with a special left- or right-pointing apostrophe.
Try copying the code into a "plain" text editor (Notepad would do fine) and re-type the ' in the code, then recompile it.
Absolutely! You can email special characters, in the Subject and the Body.
BEGIN
UTL_MAIL.send(sender => 'me#domain.com',
recipients => 'you#domain.com',
subject => 'Cards? ♠♥♦♣',
message => 'Shall we play cards? ♠♥♦♣');
END;
/
If the special characters are being replaced by "?" then either the database or the email recipient does not have a UTF8 charcaterset