Setting message STMP server with Mail.app ??

Dear MacScripters,

Sorry to bother you with these questions, but the usual Google “saturation searches” have come up with nothing. I have two questions related to emailing data from an AppleScript using Mail.app.

First, a quickie sanity check: can Mail.app ever send plain-text emails? I couldn’t find a way.

Second, I would like to allow users to use another outgoing account than their default. These AppleScripts are uploading weather data and it may be clearer for some people to use another email account than the one they use for general correspondence. No matter how a review the Mail.app dictionary, I don’t see any way to change the default SMTP server, or any way to set the SMTP server to be used for an outgoing message. Am I missing something about the object hierarchy?

Thanks in advance for any pearls of wisdom on this matter! :slight_smile:

Cheers, Edouard

Hi elegache,

Sorry I cant help you do this with Applescript, Im a bit of a novice with it myself. However, this should be relatively simple to do with a shell script. I use a free downloadable utility called “sendEmail” which you can find at http://caspian.dotconf.net/menu/Software/SendEmail/

Once you have that, you can easily create a simple shell script to send the email with your smtp server specifed. There are many advantages to this method, one being that you dont need the mail application to actually launch, it will all happen magically in the background, and faster, and plain text. If you want the trigger to be a doubleclickable applescript, just make an applescript app that does nothing but launch the shell script.

Dear rowie718 and MacScripters,

Thanks for the suggestion. Actually I had stumbled across something similar in another free program called mtcmail. It came out of this MacScripter discussion: http://macscripter.net/viewtopic.php?id=38209. mtcmail has some nice additional features over a pure UNIX utility. The main one for me is that it can lookup passwords on the Mac Keychain. So my script doesn’t pose any security concerns and I don’t have to try to get passwords out of the Keychain using AppleScript.

Still it is an installation hassle for the users of my weather station AppleScript add-ons. I had hoped there was a way to tame Mail.app a bit more using AppleScript . . . . but I guess not! :frowning:

Thanks for your reply.

Cheers, Edouard :slight_smile:

If you’ve not done that sort of thing before, go to the linked site, download sendEmail and if it doesn’t unpack, double click it to get the folder "sendEmail - v1.5.6. In the Finder type shift-command-G and enter “usr/local/bin” to get a Finder window of that folder. Move the sendEmail executable to usr/local/bin (Admin PW required), and then in the terminal type (or copy from here) “chmod +x /usr/local/bin/sendEmail” without the quotes. Return. Now it’s ready to roll. If you then (in the terminal) type /usr/local/bin/sendEmail without any arguments, you’ll get a usage page like this:

The help options you want are at the bottom so for help in addressing type:

/usr/local/bin/sendEmail --help addressing

for example.

Thanks for the mtcmail link, very cool. As for the hassle to users, you can automate the installation process. The following code would check to see if the sendEmail utility is installed already, download it and put it in the Applications folder if not:


#!/bin/bash

if [ ! -e /Applications/sendEmail-v1.56/sendEmail ]
then
cd /Applications
curl http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz -o /Applications/sendemail.tar.gz
tar -xvf /Applications/sendemail.tar.gz
rm /Applications/sendemail.tar.gz
fi

#continue with your email code here specifying full path to the utility (/Applications/sendEmail-v1.56/sendEmail) when calling it.

Still looking for more people trying the Python solution here:

http://www.j-schell.de/node/417

If you give it a try, feedback is pretty wellcome.

Jürgen

Dear Adam, rowie718, Jürgen, and MacScripters,

Thanks for all the feedback. Actually, I’ve written a rough wrapper for mtcmail that incorporates nicely into my weather station Applescript framework, so I hope I’ve got a viable substitute to Mail.app.

Yes, an installer would be a very helpful addition. Alas, what started out as some tinkering scripts have grown into over half a dozen fairly complex scripts and worse - there are users anxious to upgrade to the latest versions. I’m just way behind! So the installer will just have to wait!

Thanks again for all your help! :slight_smile:

Cheers, Edouard

HI

I am not a command line guy. But can someone suggest a script using sendEmail to email the contents of the clipboard to a single email address?

Help would be much appreciated.

Thanks

Hi

I have compiled this short script:

set sendMail to "/usr/local/bin/sendEmail"
set emailResult to (do shell script quoted form of sendMail & " -f from@gmail.com -t recipient@gmail.com -u SUBJECT_LINE_HERE -m EMAIL_MESSAGE_HERE -s smtp.gmail.com:465 -xu address@gmail.com -xp password")

But when I execute, I get this error:

Anyone know what is going on here?

I am just wanting a simple script to send a message to an email address from a Gmail account, without using Mail or other email client. Preferably with Growl notification when message successfully sent. But that finesse can wait. I need to actually be able to send the message first!!

SendEmail is installed and functions because it responds to terminal. So something else is going on here.

Thanks

Final remarK:

I had this script initially:

set sendMail to POSIX path of (path to resource "sendEmail")

But when executing, it returned error:

Hence why I gave a direct path reference in the first quoted script:

set sendMail to "/usr/local/bin/sendEmail"

Don’t know if this explains why I am having problems…

Hello!

I’d try to set up gmail as an account in apple mail. When you have done that, and made that work, then you know a lot more. Maybe even mail.app helps you configure it! :wink: I have not set up a gmail account in apple mail, but I belive you may find that the smtp port number may be different. Maybe the ssl port 587 is the right one to use, really!

Thanks for the response. I have the account set up in Mail and use port 465 without difficulty with Mail.

With my script, I did try port 25 as well, just in case, but got the same result. And 587 brings up same error (just tried) :frowning:

Cheers

Hello

Have you tried to enter the command from commandline, and does it work then?

And which directory if any are you in then, you should also pipe your environment into a file, to see if there is any variables, that sendmail depends upon. you can start by issuing the command

set |more

To have a look at them.

Maybe you should also have a sleep after your sendmail command, before returning, to give the senmail a chance to process, before the connection is teared down again. This is just a shot in the dark! :slight_smile:

Hey McUsr

Great suggestion. What was happening was that Little Snitch was blocking the perl process. So now I have it working from command line. Email successfully sent.

Thanks

:slight_smile:

Just one last issue on this. When I email the clipboard, any accented characters arriving on a windows machine are garbled.

I have tried this:

set theUnicodeText to Unicode text of (get the clipboard as record)

And I was hoping that would solve the problem, but no joy.

How does one convert text to be Windows friendly?

Cheers

Hello! :slight_smile:

man pbpaste, pbcopy, and textutil

Maybe you should try just «class UTF8», and not Unicode text first!

The correct incantation in your particular case, is described by DJ Bazzie Wazzie in the very recent thread about problems with passwords to an smb server.

I’m sorry, I meant iconv, not textutil.

I had a look at the Bazzie Wazzie post, but cannot follow it. I am afraid that shell scripting stretches my limits…

Is UTF8 a Windows format? I tried to put that into my script but could not get it to compile.

Cheers

I’m sorry, I didn’t remembert the capitalization, and guessed that AS would coerce “UTF8” to correct text, this is what I meant, and I think the character set you are looking for is iso-8859-1 (Macroman).
but give this a try.



set thetext to "æåø"
set the clipboard to thetext as «class utf8»