Action

spark mail composer

Posted by FlohGro, Last update about 2 years ago

created by @FlohGro / more on my Blog

spark mail composer

this action will present a menu for basic settings of an e-mail to compose in spark mail app.

you need to configure the recipients options in the script step of the action. therefore set the salutation and e-mail adresses in the following variables (by replacing the dummy persons

const recipients = [
    ["name with salutation", "email@adress.com"],
    ["another name with salutation", "aemail@adress.com"],
]

const ccRecipients = [
    ["name with salutation", "email@adress.com"],
    ["another name with salutation", "aemail@adress.com"],
]

const bccRecipients = [
    ["name with salutation", "email@adress.com"],
    ["another name with salutation", "aemail@adress.com"],
]

If you find this useful and want to support me you can

Buy Me A Coffee

Steps

  • script

    // spark mail
    
    // user definitions
    const recipients = [
        ["name with salutation", "email@adress.com"],
        ["another name with salutation", "aemail@adress.com"],
    ]
    
    const ccRecipients = [
        ["name with salutation", "email@adress.com"],
        ["another name with salutation", "aemail@adress.com"],
    ]
    
    const bccRecipients = [
        ["name with salutation", "email@adress.com"],
        ["another name with salutation", "aemail@adress.com"],
    ]
    
    
    
    function run() {
    
        // prompt for recipients
        let pMail = new Prompt();
        pMail.title = "set e-mail details"
    
    pMail.addTextField("subject","subject",draft.displayTitle)
    
    // recipients
        pMail.addSelect("selectedRecipients", "recipients", recipients.map(rec => rec[0]), [], true)
        pMail.addSelect("selectedCCRecipients", "cc recipients", ccRecipients.map(rec => rec[0]), [], true)
        pMail.addSelect("selectedBCCRecipients", "bcc recipients", bccRecipients.map(rec => rec[0]), [], true)
        
        pMail.addButton("create e-mail")
        if (!pMail.show()) {
            return false;
        }
    
        let selectedSubject = pMail.fieldValues["subject"];
    
        
        let selectedRecipientsSalutations = pMail.fieldValues["selectedRecipients"];
        // retrieve e-mail adresses of selecrted recipients
        let selectedRecipientsMails = [];
        for (sel of selectedRecipientsSalutations) {
    
            for (rec of recipients) {
                if (rec[0] == sel) {
                    selectedRecipientsMails.push(rec[1])
                }
            }
        }
    
    
        let selectedCCRecipientsSalutations = pMail.fieldValues["selectedCCRecipients"];
        // retrieve e-mail adresses of selecrted recipients
        let selectedCCRecipientsMails = [];
        for (sel of selectedCCRecipientsSalutations) {
    
            for (rec of recipients) {
                if (rec[0] == sel) {
                    selectedCCRecipientsMails.push(rec[1])
                }
            }
        }
    
        let selectedBCCRecipientsSalutations = pMail.fieldValues["selectedBCCRecipients"];
        // retrieve e-mail adresses of selecrted recipients
        let selectedBCCRecipientsMails = [];
        for (sel of selectedBCCRecipientsSalutations) {
    
            for (rec of recipients) {
                if (rec[0] == sel) {
                    selectedBCCRecipientsMails.push(rec[1])
                }
            }
        }
        
        // assemble basic body for mail:
        let body = ""
        if(selectedRecipientsSalutations.length > 0){
            body = selectedRecipientsSalutations.join(", ");
        }
        
        // now assemble the url for spark
        const baseURL = "readdle-spark://compose";
        let cb = CallbackURL.create();
        cb.baseURL = baseURL;
        if(selectedRecipientsMails.length > 0){
          cb.addParameter("recipient",selectedRecipientsMails.join(","));
        }
        if(selectedCCRecipientsMails.length > 0){
          cb.addParameter("cc",selectedCCRecipientsMails.join(","));
        }
        if(selectedBCCRecipientsMails.length > 0){
          cb.addParameter("bcc",selectedBCCRecipientsMails.join(","));
        }
        
        cb.addParameter("subject",selectedSubject);
        cb.addParameter("body",body);
        cb.waitForResponse = false;
        cb.open();
        return true;
    }
    
    if (!run()) {
        context.fail();
    }

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.