A newsletter sender: styled text from a cocoa window to mail

Hi folks, and nice to meet you all.
I am building a script in order to send my band newsletter to the subscribers. The script’s aim is to send an individual copy of the same message to each contact into a group in my adress book.
The script is (almost) working, and I’m doing some work to refine it…
The script is included in an AppleScript Studio project; I’ve made a cocoa window (InserisciTesto), where one inputs the tex of the message, with a button to start the script (that is theObject :wink: )
There are is a major problems, styled text…
My final aim is sending a newsletter with formatted text and attachments… But with this script the text I input gets converted in plain text… What should I do?

Here’s the code of the script:


-- Newsletter.applescript
-- Newsletter
--set NomiContatti to {}
on clicked theObject
    set gruppi to {}
    set InsiemeGruppi to {}
    set IndirizziContatti to {}
    set theSubject to "prova"
    set theBody to content of text view "typedtext" in scroll view "scroll" in window "inserisciTesto" as styled text
    --Sceglie il gruppo a cui inviare la newsletter tra i gruppi dell'address book
    set InsiemeGruppi to {}
    tell application "Address Book"
        set gruppi to every group
        repeat with girup in gruppi
            set InsiemeGruppi to InsiemeGruppi & (name of girup)
        end repeat
        set risultato to choose from list InsiemeGruppi with prompt "Scegli a che gruppo inviare la newsletter" without multiple selections allowed
        if the result is not equal to false then set Destinatari to risultato
        display dialog (Destinatari)
    end tell
    tell application "Address Book"
        set contatti to every person in group "Prova"
        repeat with tizio in contatti
            --set NomiContatti to NomiContatti & (get the name of tizio)
            try
                set IndirizziContatti to IndirizziContatti & (value of first item of email of tizio)
            end try
        end repeat
    end tell
    --estrae da Mail i vari account per poi decidere quale scegliere come mittente
    tell application "Mail"
        set listOfSenders to {}
        set everyAccount to every account
        repeat with eachAccount in everyAccount
            set everyEmailAddress to email addresses of eachAccount
            if (everyEmailAddress is not equal to missing value) then
                repeat with eachEmailAddress in everyEmailAddress
                    set listOfSenders to listOfSenders & {(full name of eachAccount & " <" & eachEmailAddress & ">") as string}
                end repeat
            end if
        end repeat
    end tell
    
    -- Prompt the user to select which account to send this message from.
    set theResult to choose from list listOfSenders with prompt ¬
        "Which account would you like to send this message from?" without multiple selections allowed
    if theResult is not equal to false then
        set theSender to item 1 of theResult
        tell application "Mail"
            --crea il nuovo messaggio
           
           
            repeat with indirizzo in IndirizziContatti
                set newMessage to make new outgoing message with properties {sender:theSender, subject:theSubject, content:theBody & return & return}
                tell newMessage
                    set visible to true
                    make new to recipient at the end of to recipients with properties {address:indirizzo}
                end tell
               
                send newMessage
            end repeat
           
            activate
        end tell
    end if
    --  Created by Tevac on Wed Oct 27 2004.
    --  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
    
    
    
end clicked

Thanks in advance for any help,
Davide

I may not understand what you are trying to do, but to me it sounds like you want to send the same message and attachments to a group of email addresses in your Address Book. This can be done directly from within Mail. If you don’t want to all of the email addresses included in each message then go to Mail’s Preferences. Go to the Composing pane and about half way down is a check box “When sending to a group, show all member addresses.” Turn this off and you should be good to go.

Again, I may not fully understand what you are trying to accomplish. Sorry if I have missed something.

Brad Bumgarner, CTA

As a matter of fact this script might seem useless, but it is not. If you include too many address (either To: or Bcc:) the SMT servers will reject your message; there are limits toi the number of recipients for a single mail. Moreover, some pop servers block your mail even if just one of the addresses is wrong…
This is the reason why I need to send a single, individual mail, with a single recipient, to each subscriber. and my onle problem now is getting styled text…
Cheers,
Davide

That makes sense to me. I don’t see anything wrong with your code (granted I haven’t looked at it with a fine-toothed comb). Just a thought here: In Mail, under Preferences, in the Composing section, what is the Format set to? That’s all that I can think of.

Hope this helps,
Brad Bumgarner, CTA

Thanks Brad :slight_smile:
I had actualy thought that myself, but Mail preferences are set to “styled text”; still, the text loses its features when transported from the cocoa window to the new mail…
I was wondering if this could be due to some xcode setting, or some cocoa property…
Any suggestion?
Cheers,
Davide

Bummer! That’s the only thing I could think of. I haven’t done much Mail.app scripting and what I have done hasn’t required styled text.

Good luck,
Brad Bumgarner, CTA