-1

I'm trying to use applescript to do two things:

  1. Create an account in Mail.app
  2. Using that account, send an email in Mail.app

I'm having an issue with creating an account on Mail.app mainly because theres no "SMTP server", and I'm trying to use Yahoo. No matter what I try, I can't get Applescript to automatically add yahoo as the smtp outgoing server. Here's my code:

tell application "Mail"
    set AccountName to "account_name"
    set newacct to make new pop account with properties {name:AccountName, user name:"account_name@yahoo.com", server name:"mail.yahoo.com"}
    tell newacct
        set password to "ThePassword"
        set full name to AccountName
        set email addresses to {"account_name@yahoo.com"}
        set port to 995
        set uses ssl to true
    end tell

    set addsmtp to make new smtp server with properties {server name:"smtp.mail.yahoo.com", user name:"account_name@yahoo.com"}
    tell addsmtp
        set password to "ThePassword"
        set uses ssl to true
        set port to 465
    end tell
    set smtp server of newacct to addsmtp
end tell
  • 1
    Why exactly are you trying to do this? I ask because it wreaks of spam. It also violates Yahoo! Mail EULA. – user10355 Nov 14 '14 at 17:52
  • Did you try set smtp server of newacct to smtp server addsmtp – tubedogg Nov 14 '14 at 17:54
  • @tubedogg tried, got error: Mail got an error: Can’t make smtp server \"smtp.mail.yahoo.com\" into type integer." number -1700 from smtp server "smtp.mail.yahoo.com" to integer – erictsai626 Nov 14 '14 at 18:18
  • I posted some revised code below, please try and let me know if it works. – tubedogg Nov 14 '14 at 18:50
  • Welcome to Ask Different. Unless one script has to perform both functions, it would be best to ask two questions. The solution to sending email might not come from the same person as the one to create the account in the first place. – bmike Nov 14 '14 at 19:18
1

Everything I've read (granted most of it, quite old) indicates that you need to include the words "smtp server" before "addsmtp", even though it should be quite obvious from the context.

There is also apparently a bug in the way AppleScript handles references to the new server.

Remove from the first set smtp server to the end of the script, and replace with this:

    set smtpservername to "smtp.mail.yahoo.com"
    set smtpusername to "account_name@yahoo.com"
    set addsmtp to make new smtp server with properties {server name: smtpservername}
    tell addsmtp
        set authentication to password
        set password to "ThePassword"
        set uses ssl to true
        set port to 465
        set user name to smtpusername
    end tell
    set newsmtpserver to smtp server (smtpservername & ":" & smtpusername)
    set smtp server of newacct to smtp server newsmtpserver
end tell
| improve this answer | |
0

I know this question is old but I've been having some similar problems and found this question in my search for answers.

Perhaps this changed in recent version of macOS, but in the Mail AppleScript Dictionary in Catalina at least it appears that the correct syntax for setting the smtp/outgoing server for an imap account is:

set delivery account of <imap account>...

as opposed to the OPs:

set smtp server of <imap account>...

I haven't actually tried it myself because I'm having all kinds of other Mail AppleScript problems, which I'll post one or more separate questions about in a bit. If anyone else can test this I'd love to confirm this solves the OPs problem.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .