Generating eMails with attachments

Viewing 4 reply threads
  • Author
    Posts
  • November 21, 2019 at 5:44 AM #38150

    Eddy
    Participant

    Hi Folks!

    We are using TapForms also as a CRM-System.

    Therefore we let TapForms generate Emails for us. We are using a script, that generates a “mailto” phrase including address, subject and body. This headers are collected from TapForms fields. This works great.

    And here is the task:

    Sometimes we have to send our clients/guests a PDF (standard contract-template, checklist etc.). Of course, we store these standard PDFs in our CRM-System, i. e. TapForms. But there is no way to generate an email with an attachment by using the “mailto”-method.

    What we need is a button inside a form, that creates an email with an attached file, coming out of a attached-file-field.

    Any ideas?

    Thanks in advance, Eddy

    November 22, 2019 at 1:14 AM #38167

    Brendan
    Keymaster

    There’s no functionality for attaching a file to an email from within a Script.

    However, on the iOS version, when you email a record, Tap Forms will include all photos and file attachments as attachments to the email. That functionality doesn’t exist on the Mac version though.

    November 23, 2019 at 1:54 PM #38227

    Eddy
    Participant

    Thanks Brendan, for your promt answer!

    I found a way to generate mails from Tapforms to MacOS by using Javascript.

    Like this:

    Mail = Application('com.apple.Mail')
    message = Mail.OutgoingMessage().make()
    message.visible = true
    message.toRecipients.push(Mail.Recipient({ address: "foo.bar@example.com" }))
    message.subject = "Testing JXA"
    message.content = "Foo bar baz"
    
    attachment = Mail.Attachment({ fileName: "/Users/myname/Desktop/test.pdf" })
    message.attachments.push(attachment)

    Or, even better by using the PATH-Command:

    Mail = Application('com.apple.Mail')
    message = Mail.OutgoingMessage().make()
    message.visible = true
    message.toRecipients.push(Mail.Recipient({ address: "foo.bar@example.com" }))
    message.subject = "Testing JXA"
    message.content = "Foo bar baz"
    
    attachment = Mail.Attachment({ fileName: Path("/Users/myname/Desktop/if the file has spaces in it test.pdf") })
    message.attachments.push(attachment)


    The question is now:
    How can I address the file / path inside Tapforms correctly?

    Thanks in advance:

    Eddy

    November 26, 2019 at 2:10 AM #38305

    Brendan
    Keymaster

    Hi Eddy,

    Did you try this from within Tap Forms? I just tried, but I get Can't find variable Application error. I’m not sure that Application is supported from within the JavaScriptCore framework.

    November 26, 2019 at 2:15 AM #38306

    Brendan
    Keymaster

    I know where you got this from:

    https://stackoverflow.com/questions/27746418/send-email-with-attachment-using-javascript-for-automation

    But that’s JavaScript for Automation. That is, from AppleScript (but using JavaScript instead of the AppleScript language).

    That won’t work from within JavaScriptCore, which is what Tap Forms uses.

Viewing 4 reply threads

You must be logged in to reply to this topic.