Running applescript on different users account.

Hello,

I have made an applescript to send bulk mail as individual emails the only problem is that nothing can be done while it is running as it uses keystroke and the clipboard.

I have tried running it on another user but it seems to idle while that user is inactive now I would like to know to let the script run off in the back ground of another user instead of idling until the user goes back to that profile.

Would be great to see if this is possible because it could be sending unto 250 emails at a time. luckily (kind of) I made a certification error a while back so Mac’s mail has to verify before sending so it will not send anything while I am testing this and it also ignores that window while it is going on.

Hopefing someone will know how to do this!

Thanks,
Bruce

Does it have to be send by Mail? You can send mails by using a sendmail command line utility.

well if there is anyway to set the body of the message as the contents of a webpage then Im sure it can be but I have not been able to see this done yet so I am not sure.

At the moment the body of the message is made via safari opening the page then copy and pasting it into the body then it runs a check to see if that page is open if so it just pastes the clipboard into the body of the message.

Thanks,
Bruce

Like you do on http you need to set some SMTP headers like mime type and mime version. It’s not for the mail server but it’s for the mail client who will read your mail and show the content correctly. You need something like this:

set mailMessage to quoted form of "From: me@example.org
To: me@gmail.com
Subject: MIME Test
Mime-Version: 1.0
Content-Type: text/html

<html>
<body>
This is a test.
</body>
</html>"

do shell script "sendmail -t <<<" & mailMessage

although that does look like a good idea it has a possibility of getting a bit messy and also I have not been told how often the news letter is going to be changed (as there is plans for it to be sent out weekly it could be quite often) if it where to be changed often I would keep having to send a different applescript for the person who is sending out the bulk mail every time it changed.

Is there a possible way around it?

Thanks,
Bruce

EDIT: Just tried it with the current news letter and it would not work was getting a lot of expression and syntax errors.

I’ve just showed an example. You can of course make it all dynamic while my example completely static, just to show you how it works in it’s simplest form.

That means that you have typos in your code, you have to escape special characters in AppleScript.

<div class="cssname" id="identifier"></div>

has to written in in AppleScript as:

"<div class=\"cssname\" id=\"identifier\"></div>"

I just tried putting back slashes (is that correct?) \

in front of/before quotation marks in my html and it managed to compile it all yet when I run it the result is “” and no email has been sent.

Am I missing something?

Thanks,
Bruce

When sendmail returns “” it means that you have filled everything correctly, but th email server is probably denying something or missing some extra headers information or other parameters. Try the option -v with sendmail. When the mail isn’t send it will send a report to your local mail client. Which is probably your user@localhostname.local which can be accessed by using the mail command line utility which can be accessed by the terminal.

My email provider can be a bit fiddly with sending emails and doesn’t always provide the right information when setting it up and will try the -v option with sendmail and I shall get back to you on that one.

Thanks,
Bruce

Just tried using -v with sendmail and I get the result “Mail Delivery Status Report will be mailed to .” and no message has been sent again.

Know any reason as to why?

Thanks,
Bruce

Aha the part was the give away.

I forgot to tell you that you need to set the relay host of the mail server in a config file. I have my own mail server and don’t need these settings because my mail server is inside my own network.

in /etc/postfix there is a file main.cf that is the configuration file to send and receive mail. Go to the seciont “# INTERNET OR INTRANET” and fill in the correct relay host. If you’re server requires a login name and password to send mails like you need for gmail accounts, you can find a step by step tutorial here

Hi,

Sorry for the late reply, I have looked through the file and found “# INTERNET OR INTRANET” and found that I need to change

#relayhost = $mydomain
#relayhost = [gateway.my.domain]
#relayhost = [mailserver.isp.tld]
#relayhost = uucphost
#relayhost = [an.ip.add.ress]

sorry I am really new to changing config files within postfix and I’m not sure what goes where to me it is a bit confusing.

If you can help that would be great.

I had a look at the tutorial and the confused me even more.

Sorry for being such a pain its probably very simple to you.

Thanks,
Bruce

Not at all!

It’s confusing. Each line starting with ‘#’ is commentary, those relay host settings are just examples in the comments. My advice would be not to change any comments at all but add one new line below like one of those examples but this time don’t start with a hash.

I think the only thing I knew there was that ‘#’ is used for commenting in config files.
No it was more what information goes where.

I have tried the tutorial unfortunately along the way I had the directory opened in finder and it has messed the permissions up so I can’t make the .db file for the password and I have tried repairing the permissions yet it still was saying access denied when running

sudo postmap /etc/postfix/sasl_passwd

.

any idea as to why that is happening?

Thanks,
Bruce

I don’t know the mail account so I don’t know either ;). The same information as the smtp server settings in application mail goes there.

The BSD system folders are not used to be handled by the Finder. The finder is a process running as a console user and not as a system administrator (note: system administrator is something else than administrator in Mac OS X). Therefore don’t do any file handling in the Finder for files in folders like /etc, /var, /usr for example. Use the terminal instead. If editing files with vi is too hard, you can also try nano wich is an much more easier text editor. So type in terminal

sudo nano /etc/postfix/main.cf

I have managed to be able to look up how to save edit using Vi now and I managed to get through the tutorial and everything is running find and it managed to build the .db of the user and password needed it but applescript is still returning the same message “Mail Delivery Status Report will be mailed to .”

any idea why this could be?

Thanks,
Bruce

P.S. I used the tutorial as the mail server I use needes user and password.

did you reload the prostfix correctly?

sudo postfix reload

You could also try to enforce the sender like this, not required on my machine but it could be on some:

set mailMessage to quoted form of "Subject: MIME Test
Mime-Version: 1.0
Content-Type: text/html

<html>
<body>
This is a test.
</body>
</html>"

do shell script "sendmail -f from@example.com to@example.com <<<" & mailMessage

yes I have run sudo postfix reload
sometimes it says “postfix/postfix-script: fatal: the Postfix mail system is not running”

but then I start postfix using:

sudo launchctl launchd% start org.postfix.master launchd% quit
and then when i reload it just refreshes but I will try your code for forced sending.

Thanks,
Bruce

Just ran it and I get the result back “”

do I have to keep the -t and -v in the shell script?

Thanks,
Bruce

The -t means that sendmail has to parse recipients from the mail headers, now we have filled them on the command line we have to remove this option from the command line. We have instructed by editing main.cf that we have a relay server. Mail messages will be send to mail on the command line (do you see any mails there) or you have to look in the /var/log/mail.log and see if you see somthing like:

uid=501 from=<from@example.com> message-id=<20140709124321.62B2FCC388@hostname.local> from=<from@example.com>, size=413, nrcpt=1 (queue active) to=<to@example.com>, relay=smtp.example.com[x.x.x.x]:25, delay=0.22, delays=0/0/0.08/0.13, dsn=2.0.0, status=sent (250 2.0.0 s69CiQeb015153 Message accepted for delivery)