I did find the External in my RunRev Ext folder under tsNet_Indy_1.3.4
Here is the code:
Code: Select all
local tUrl, tEmailMessage, tSender, tRecipient, tSettings, tFilePath, tFileName, tFileData, tResult, tBytes, tResponseHeaders
put "smtp://mail.mfelkerco.com:587/" into tUrl
put "Attached is a new PDA Form from Aflac" into tEmailMessage
put tPDFPath into tFilePath
set the itemDel to slash
put the last item of tFilePath into tFileName
put URL("binfile:" & tFilePath) into tFileData
put "xxxxxxx" into tSettings["username"]
put "xxxxxxxxxxx" into tSettings["password"]
put "email address" into tSender
put "email address" & cr into tRecipient
put "email address" after tRecipient
-- Enable TLS for SMTP
put true into tSettings["use_ssl"]
-- create the smtp message
put createSmtpMessage(tTo, tCc, tSender, tSubject, tMessage, tMessageHTML, tFileName, tFileData) into tPostData
-- send email
put tsNetSmtpSync(tURL, tSender, tRecipients, tPostData, tResponseHeaders,tBytes,tSettings) into tResult
if the first word of tResult is "tsneterr:" then
answer "Error" && tResult && "returned from server"
else
answer "E-mail sent"
end if
And the function:
Code: Select all
Function createSmtpMessage pTo, pCc, pFrom, pSubject, pMessage, pMessageHTML, tFileName, tFileData
put "Date:" && the internet date & cr into tPostData
put "From:" && pFrom & cr after tPostData
put "To: " after tPostData
repeat for each line tRecipient in pTo
put tRecipient & ", " after tPostData
end repeat
delete char -1 of tPostData
put cr after tPostData
put "Cc: " after tPostData
repeat for each line tRecipient in pCC
put tRecipient & ", " after tPostData
end repeat
delete char -1 of tPostData
put cr after tPostData
put "Boundary." & the seconds into tBoundary
-- Create a multi-part MIME message
put "MIME-Version: 1.0" & cr after tPostData
put "Content-Type: multipart/mixed;" & cr after tPostData
put " boundary=" & quote & tBoundary & quote & cr after tPostData
--put "Subject: "&"=?UTF-8?B?"& base64Encode (textEncode(pSubject,"UTF-8"))&"?=" & cr & cr after tPostData
--The above was the original line.
--The base64encode function wraps the encoded data at 72 characters.
--So if the string, which is returned by that function, has more than 72 characters, then you have to remove the CR(s) from the returned string.
--Otherwise the CR breaks the smtp header and the subject is not displayed correctly in the email or more worse could happen.
-- So better use something like this:
put base64Encode (textEncode(pSubject,"UTF-8")) into pSubject
-- replace CR right away
-- Of course we could first check if the number of chars is >72, but why? If it´s there it will be replaced. If not, nothing happens.
replace cr with "" in pSubject
put "Subject: "&"=?UTF-8?B?"& pSubject &"?=" & cr & cr after tPostData
put "This is a multi-part message in MIME format." & cr after tPostData
-- Add the first "part" of the message
put "--" & tBoundary & cr after tPostData
-- Inside this part, we want both the HTML and plain text alternatives
put "Content-Type: multipart/alternative;" & cr after tPostData
put " boundary=" & quote & tBoundary & "_mesg" & quote & cr & cr after tPostData
-- The plain text version
put "--" & tBoundary & "_mesg" & cr after tPostData
put "Content-Type: text/plain; charset=utf-8" & cr after tPostData
put "Content-Transfer-Encoding: quoted-printable" & cr & cr after tPostData
put textEncode(pMessage, "UTF-8") & cr & cr after tPostData
-- The HTML version
put "--" & tBoundary & "_mesg" & cr after tPostData
put "Content-Type: text/html; charset=utf-8" & cr after tPostData
put "Content-Transfer-Encoding: quoted-printable" & cr & cr after tPostData
put textEncode(pMessageHTML, "UTF-8") & cr & cr after tPostData
put "--" & tBoundary & "_mesg--" & cr & cr after tPostData
if tFileName is not empty then
put "--" & tBoundary & cr after tPostData
put "Content-Type: application/pdf;" & cr after tPostData
put " name="& quote & tFileName & quote & cr after tPostData
put "Content-Transfer-Encoding: base64" & cr after tPostData
put "Content-Disposition: attachment;" & cr after tPostData
put " filename="& quote & tFileName & quote & cr & cr after tPostData
put base64encode(tFileData) & cr & cr after tPostData
end if
-- Add the closing "part" tag
put "--" & tBoundary & "--" & cr after tPostData
return tPostData
end createSmtpMessage
I found it here:
Code: Select all
https://forums.livecode.com/viewtopic.php?t=28503
Code: Select all
Error tsneterr: (55) RCPT failed: 501
returned from server
If there is another, simpler way to send an email with a pdf attached in LiveCode NOT using Thunderbird or any 3rd party software, i'm all ears.
Thanks.
Mike