简体   繁体   中英

AppleScript for sending emails from a list in Excel

I don't know AppleScript at all so thanks in advance for any help offered on this question. I'm on my Macbook Pro laptop with the latest version of OSX installed. I have an Excel spreadsheet (I could use numbers if that makes it easier) with two columns.

FirstName        Email
------------     -----------------
Ken              blah@blah.com
Mike             blahblah@blahblah.com

This is my customer list and I want to send them an email. Unfortunately I don't have this list in an autoresponder so I have to send the emails one by one.

I know that I could whip up a PHP script to send the emails, however there are issues with email deliverability when doing it this way.

I want to write an AppleScript that processes my spreadsheet one row at a time and sends a message. The message would be something like this:

Subject: How’s it going?

Hi Ken

It’s been a while since I sold you that defective widget from China. 
If you need more defective elctronics I’m here for you. Just give me 
a call at xxx-xxx-xxxx. 

Sincerely

Ken

The AppleScript would read the name and email address from one row of the spreadsheet and send this email, filling in name and email address, using the standard apple mail program.

After sending the message I want the script to wait 60 seconds. Then send another email.

This needs to happen until a blank row is encountered.

My first question… Is this possible? If possible how do I do it?

Also is there a better way to do what I'm trying to do?

Thanks

There's probably a better way to do this, but couldn't you just copy the addresses as TSV or CSV?

set addresses to "Ken;blah@blah.com
Mike;blahblah@blahblah.com"
set text item delimiters to ";"
repeat with l in paragraphs of addresses
    tell application "Mail"
        tell (make new outgoing message)
            set subject to "subject"
            set content to "Hi " & text item 1 of l & linefeed & linefeed & "..."
            make new to recipient at end of to recipients with properties {name:text item 1 of l, address:text item 2 of l}
            send
            delay (random number) * 100
        end tell
    end tell
end repeat

Try:

set {firstName, eAddress} to getData()

repeat with i from 1 to count firstName
    tell application "Mail"
        activate
        set mymail to make new outgoing message at the beginning of outgoing messages with properties {subject:"How’s it going?"}
        tell mymail
            make new to recipient at beginning of to recipients with properties {address:item i of eAddress}

            set content to "Hi " & item i of firstName & "

It’s been a while since I sold you that defective widget from China. 
If you need more defective elctronics I’m here for you. Just give me 
a call at xxx-xxx-xxxx. 

Sincerely

Ken"
        end tell
        --show message window (otherwise it's hidden)
        set visible of mymail to true
        --bring Mail to front
        activate
        send mymail
    end tell
end repeat


on getData()
    set colA to {}
    set colB to {}
    tell application "Microsoft Excel"

        activate
        tell active sheet
            set lastRow to first row index of (get end (last cell of column 1) direction toward the top)

            repeat with i from 3 to lastRow
                set end of colA to (value of range ("A" & i))
                set end of colB to (value of range ("B" & i))
            end repeat
        end tell
    end tell

    return {colA, colB}
end getData

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM