Skip to content

Instantly share code, notes, and snippets.

@madpink
Created September 28, 2016 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madpink/707ff7653998ba1f62fda7f0c54d05f7 to your computer and use it in GitHub Desktop.
Save madpink/707ff7653998ba1f62fda7f0c54d05f7 to your computer and use it in GitHub Desktop.
command sendThisMessage
-- For the record, this is not a real username/password for Amazon SES
put "smtps://email-smtp.us-east-1.amazonaws.com" into tURL
put "XBCGUEHJDSJADJJDJS" into tSettings["username"]
put "AIjQCX5qs9iiAk+xqcRsj7D4B/mwRuAEMfrE8oWLmKAJ" into tSettings["password"]
----put TRUE into tSettings["use_ssl"] --uncomment if needed
--Note that from_name is optional
put "Arthur Dent" into tHeaderData["from_name"]
put "arthur@somewhere.galaxy" into tHeaderData["from"]
--Specify the number of recipients and their email addresses... note that to_name is optional
put 2 into tHeaderData["recipients"]
put "Zaphod Beeblebrox" into tHeaderData["to_name"][1]
put "zaphod23@somewhere.galaxy" into tHeaderData["to"][1]
put "Ford Prefect" into tHeaderData["to_name"][2]
put "fordprefect@somewhere.galaxy" into tHeaderData["to"][2]
--Specify the content type of the message
----type can be plain or html... theoretically rtf too, untested
----charset can be left blank if just using"utf-8" (recommened)
put "html" into tHeaderData["type"]
put "utf-8" into tHeaderData["charset"]
put "So long" into tHeaderData["subject"]
put "<p>and thanks for all the fish</p>" into tData
put emailMessageHeaders(tHeaderData) before tData
put tsNetSmtpSync(tURL, tHeaderData["from"], tHeaderData["to"][1], tData, tOutHeaders, tBytes, tSettings) into tResult["server_response"]
put tOutHeaders into tResult["outputHeaders"]
put tBytes into tResult["bytes"]
if char 1 to 8 of tResult["server_response"] is not "tsneterr" then
put "OK" into tResult["server_response"]
else
replace cr with space in tResult["server_response"]
end if
end sendThisMessage
function emailMessageHeaders pHeaderData
if pHeaderData["type"] is empty then put "plain" into pHeaderData["type"]
if pHeaderData["charset"] is empty then put "utf-8" into pHeaderData["charset"]
put "Content-Type: text/" & pHeaderData["type"] & "; charset=" & pHeaderData["charset"] & cr into tHeader
put "Date:" && the internet date & cr after tHeader
if pHeaderData["from_name"] is empty then
put "From:" && pHeaderData["from"] & cr after tHeader
else
put "From:" && pHeaderData["from_name"] && "<" & pHeaderData["from"] & ">" & cr after tHeader
end if
if pHeaderData["sender"] is not empty then put "sender:" && pHeaderData["sender"] & cr after tHeader
if pHeaderData["reply-to"] is not empty then put "reply-to:" && pHeaderData["reply_to"] & cr after tHeader
if pHeaderData["recipients"] is empty then put 1 into pHeaderData["recipients"]
put "To: " after tHeader
repeat with x=1 to pHeaderData["recipients"]
if pHeaderData["to_name"][x] is empty then
put pHeaderData["to"][x] after tHeader
else
put pHeaderData["to_name"][x] && "<" & pHeaderData["to"][x] & ">" after tHeader
end if
if x < pHeaderData["recipients"] then put comma after tHeader else put cr after tHeader
end repeat
if pHeaderData["ccrecipients"] is not empty then
put "CC: " after tHeader
repeat with x=1 to pHeaderData["ccrecipients"]
if pHeaderData["cc_name"][x] is empty then
put pHeaderData["cc"][x] after tHeader
else
put pHeaderData["cc_name"][x] && "<" & pHeaderData["cc"][x] & ">" after tHeader
end if
if x < pHeaderData["ccrecipients"] then put comma after tHeader else put cr after tHeader
end repeat
end if
if pHeaderData["bccrecipients"] is not empty then
put "BCC: " after tHeader
repeat with x=1 to pHeaderData["bccrecipients"]
if pHeaderData["bcc_name"][x] is empty then
put pHeaderData["bcc"][x] after tHeader
else
put pHeaderData["bcc_name"][x] && "<" & pHeaderData["bcc"][x] & ">" after tHeader
end if
if x < pHeaderData["bccrecipients"] then put comma after tHeader else put cr after tHeader
end repeat
end if
put mimeEncoded(pHeaderData["charset"],"B",pHeaderData["subject"]) into tSubject
put "Subject: " & tSubject &cr after tHeader
put cr after tHeader
return tHeader
end emailMessageHeaders
function mimeEncoded pCharSet pType pLine
--pType can B or Q (base64 or Q-encoding)
put "=?" & pCharSet & "?" & pType & "?" into tEncodedLine
if pType is "B" then
put base64Encode (textEncode(pLine,pCharSet)) into pLine
else if pType is "Q" then
--Q-encoding is on my todo list... don't use it for now
replace space with "_" in pLine
end if
put pLine & "?=" after tEncodedLine
return tEncodedLine
end mimeEncoded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment