Re: Mailing with a do shell script
Re: Mailing with a do shell script
- Subject: Re: Mailing with a do shell script
- From: Lars de Runtz <email@hidden>
- Date: Thu, 15 Dec 2005 14:28:55 -0800
<AppleScript>
--Lars DeRuntz, standard disclaimer
--variables that will change often
--remember to escape the quotes with a backslash
set TheTo to "email@hidden"
set TheCc to ""
set TheBcc to ""
set TheFrom to "email@hidden"
set TheSubject to "TEST sendmail directly from AppleScript"
set TheBody to "<HTML>
<HEAD><style type=\"text/css\">
<!--
.inputData {color: #000000; font-family: Arial; font-weight: normal; font-size: 9.0pt;}
.inputFieldName {color: #000000; font-family: Arial; font-weight: bold; font-size: 9.0pt;}
--></style></HEAD>
<BODY BGCOLOR=LIGHTGREY>
<CENTER><table width=\"75%\" border=\"0\" cellpadding=\"3\" cellspacing=\"2\">
<tr>
<td bgcolor=#FFFFFF class=\"inputFieldName\">Lars</td>
<td bgcolor=#EEEEEE></td>
<td bgcolor=#DDDDDD class=\"inputFieldName\">DeRuntz</td>
</tr>
<tr>
<td bgcolor=#EEEEEE></td>
<td bgcolor=#DDDDDD class=\"inputData\">This is a test. -Lars</td>
<td bgcolor=#CCCCCC></td>
</tr>
<tr>
<td bgcolor=#DDDDDD class=\"inputFieldName\">Modus</td>
<td bgcolor=#CCCCCC></td>
<td bgcolor=#BBBBBB class=\"inputFieldName\">Link</td>
</tr>
</table></CENTER>
</BODY>
</HTML>"
--variables that will remain constant
set lf to ASCII character 10
set cr to ASCII character 13
--temporary message file
set MacPathAndFile to "OSX:Users:LarsDeRuntz:Desktop:testfile"
set UnixPathAndFile to "/Users/LarsDeRuntz/Desktop/testfile"
--get current date from shell in proper format
set EMailDate to (do shell script "date \"+%a, %e %b %Y %H:%M:%S %Z\" ; ")
--equal signs need to be changed to =3D in HTML body or they won't get recognized
set TheBody to TheBody, "=", "=3D")
--Add headers to create what sendmail needs
set TheCode to "MIME-Version: 1.0
Content-Type: text/html; charset=\"iso-8859-1\"
Content-Transfer-Encoding: quoted-printable
content-class: urn:content-classes:message
Subject: " & TheSubject & "
Date: " & EMailDate & "
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
X-Priority: 1
Priority: Urgent
Importance: high
X-Message-Flag: Lars DeRuntz - sendmail - AppleScript
Errors-To: email@hidden
From: " & TheFrom & "
To: " & TheTo & "
Cc: " & TheCc & "
Bcc: " & TheBcc & "
" & TheBody
--convert carriage returns to newlines
set TheCode to TheCode, cr, lf)
--write out message to file
MacPathAndFile, TheCode)
--send the text of the message file to shell sendmail, send the sendmail queue, then remove the message file
do shell script "cat " & UnixPathAndFile & " | sendmail ; sendmail -q ; rm " & UnixPathAndFile & " ; "
--End
--subroutines
--Substitute function makes life easier
on TheText, OldText, NewText)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to OldText
set NewList to text items of TheText as list
set AppleScript's text item delimiters to NewText
set TheText to text items of NewList as string
set AppleScript's text item delimiters to tid
return TheText
end Substitute
--Make a file function can be used over and over
on FileName, FileContents)
tell application "Finder"
try
close access file FileName
on error
--
end try
open for access file FileName with write permission
write FileContents to file FileName
close access file FileName
end tell
end MakeAFile
</AppleScript>
On Dec 15, 2005, at 9:21 AM, Jay Louvion wrote:
On 14/12/05 22:31, "de Runtz, Lars" <email@hidden> wrote:
Create a file with basic headers
And what would that look like ? I’m sorry to be such a newbie on this, but having been through so much trial and error with the command line, I really would appreciate a solid example to be able to adapt it to my needs.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden