Running applescript on different users account.

I know it does work :cool:

Just somewhere between the other headers.

You can test it also otherwise:

  • make a mail in Mail.app and fill in everything including subject en to whom you want to send the mail to.
  • save the mail somewhere on your machine (let’s say /mymail.eml), be sure you don’t save it as rtf but as source mail
  • then run the following script:
do shell script "sendmail -t </mymail.eml"

I have tried putting at the bottom and between the subject and body and before the subject.

If I try it outside of the quotation marks at the top I get Syntax Error: A “:” can’t go after this identifier.

Everywhere else I have tried it send the mail yet it still sends as text instead of the page I got the code off.

Thanks,
Bruce

I just tried sending a message file using:

tell application "System Events" to set parentFolder to POSIX path of container of (path to me)
set filename to "Test.eml"
set mail to (parentFolder & "/" & filename)

do shell script "sendmail -t mail"

Unfortunately the result is “” and no email has been sent!

any reason as to why this is?

Thanks,
Bruce

you have to pass the variable mail, not the literal string “mail”.
And add always quoted form of to handle space characters in the path properly


do shell script "sendmail -t " & quoted form of mail

Just tried it got this error:
Applescript error:
sendmail: illegal option – /
sendmail: illegal option – s
sendmail: illegal option – /
sendmail: fatal: usage: sendmail [options]

EDIT:

Never mind didn’t include a space between -t "

I don’t know the syntax of sendmail, but in post #26 there is an < character in front of the path


do shell script "sendmail -t <" & quoted form of mail

Sorry for late response, it’s our loss against Argentina from last night.

What you need to to i slike Stefan said bit the file contents needs to be send to sendmail, not the file name.

tell application "System Events" to set parentFolder to POSIX path of container of (path to me)
set filename to "Test.eml"
set mail to (parentFolder & "/" & filename)

do shell script "sendmail -t <" & quoted form of mail

edit: Like Stefan said. He was posting while was writing, sorry for double post.

Thanks guys for your responses but it still is showing “” and not sending anything.

I done it with and without < and it hasn’t made a difference.

tell application "System Events" to set parentFolder to POSIX path of container of (path to me)
set filename to "Test.eml"
set message to parentFolder & "/" & filename

do shell script "sendmail -t <" & quoted form of message

Just look in the console and see what it says there.

Hi,

Sorry for the late reply had a long weekend.

Before I left I did this and I noticed it worked but it ended up in both inboxes


tell application "System Events" to set parentFolder to POSIX path of container of (path to me)
set filename to "Test.eml"
set message to parentFolder & "/" & filename

do shell script "sendmail -t email@email.co.uk to address@address.com <" & quoted form of message

when the first email address is not there it send but it receives saying no sender.

any idea why this could be?

to is not a valid command line argument for sendmail.

Hi, tried it with out the to and now Im not getting anything at all.

Any reason as to why?

Thanks,
Bruce

Have you looked into your console? If there is anything wrong with the markup of the Mail or communication with the SMTP server you have to look there.

here is the log for it, if its right?

Thanks,
Bruce

That is right. The 250 OK message indicates that everything has worked properly. A common issue now is that the mail could not be delivered to the proper mail box, something that is handled by the remote server (smtp.emailsrvr.com) and not by sendmail. You have defined a sender but make sure that <server@osx server domain.private> also accepts bounce backs from other mail servers (an informative mail that indicates what went wrong on the remote server). Another common issue is a spam filter who catches the mail and doesn’t deliver the mail properly in the inbox.

Hi,

The server@osx serverdomain.private is the name of the computer (well changed) because a while ago I was trying to set up a VPN not knowing the ISP blocked most ports and won’t allow you to open them and when I had apple tech support to help me they changed the name of the computer to a no-ip domain which was being used to redirect to the IP as it was not static at the time so thats become the computers name.

Anyway thats the address that showed up when I didn’t configure the file properly but now that I have and have defined my email address and SMTP server it should not be showing that although it seems to be trying to send emails through OSX’s email utility which won’t work as I do not have it enabled but it should not be trying to do that anyway any reason as to why that is?

Thanks,
Bruce

here is the smtp server

and the sasl_passwd file

EDIT:
Didn’t want to bump and did not realise that the SMTP server in the sasl_passwd file needed a port will give it another try in a second
EDIT 2:
Still not sending and just looked at the log file, it is still trying to send from OSX server mail and not from the defined email address rather strange considering it was working at one point and no changed have been made.

Right,

So I have managed to be able to get it to work using -f and -t.

Now I want to be able to use a bit of code I got from a previous forum post which repeats the script changing the recipient every time and ending the script when it reaches the end of the file.

This is what I have at the moment:


tell application "System Events" to set parentFolder to POSIX path of container of (path to me)
set filename to "Test.eml"
set message to parentFolder & "/" & filename

display dialog "Choose Mail Group" buttons {"test", "Test Bulk", "bulktest"}
if result = {button returned:"test"} then
	set theGroups to "test"
	set theFileName to "test.csv"
	set theEmailGroup to paragraphs of (do shell script ("egrep -o '\\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z0-9.-]+' " & quoted form of (parentFolder & "/" & theFileName)))
end if
set EmailAddresses to theEmailGroup
repeat with i from 1 to count of EmailAddresses
	
	
	do shell script "sendmail -f my@email.co.uk -t  & EmailAddresses <" & quoted form of message
end repeat

I can’t seem to get the variable EmailAddresses to work as it is within the quotation marks and when I move it out of them the script expects end of line.

Can anybody help with this?

Thanks,
Bruce

probably


 do shell script "sendmail -f my@email.co.uk -t " & item i of EmailAddresses & " <" & quoted form of message

ah, I was almost there when i put it outside of the quotation marks, was just missing the & at the end of it.

Thanks for that :slight_smile:

Bruce