Creating an email with trigger

556 views
Skip to first unread message

Horst Liebermann

unread,
Dec 2, 2016, 4:19:40 AM12/2/16
to mementodatabase
To improve processes using my memento database I need to create an email.with some generated text ( by calculation field) and with an attached Foto.
Anybody could help to find a solution similar to the SMS example in help for triggers? Would be great!
Horst

Bill Crews

unread,
Dec 2, 2016, 5:53:10 AM12/2/16
to mementodatabase
If you Google "gmail intent Android", you'll see some StackOverflow forum postings, and there's also an article or two from Google for Android app developers. The code may be in Java, so mainly lift the strings to send and craft your own JavaScript around them. Note the age of each article (things can change), and you might run into dependencies on Java classes that could be a problem (like com.google.android.gm?). So, it might turn into a project to get it to work (OR it might not).

If you choose to try it, I would enjoy reading your results, if you don't mind posting it back here.

OR maybe all this is much easier and someone will post the exact answer for us here; I hope so.

Horst Liebermann

unread,
Dec 2, 2016, 1:54:33 PM12/2/16
to mementodatabase
What I found is
https://youtu.be/E6LjSjJb5T4
Not shure, if this will solve my problem.
Message has been deleted

Bill Crews

unread,
Dec 3, 2016, 4:19:45 PM12/3/16
to mementodatabase
The answer was provided by Eugene Kartoyev, which I very much appreciate, but his message appears to have been deleted, so I will try to provide:

I would generally send an email from an After script, once you know that something took place, and now you want to send notification of it. The script will run asynchronously.

So, let's use the case of sending a message whenever an entry in library A is either created or updated. So, add two triggers into A, one for event Creating a new entry and phase After saving the entry and the other for event Updating an existing entry and phase After saving the entry. Put the same script in each, though you make a small change, if you want. Here's the script.

CAVEAT: It's probably easy (like yet another i.extra() call with a path name), but I don't know how to add an attachment to the message. I hope someone will respond with that trick, as well.

var i = intent("android.intent.action.SENDTO");
i.data("mailto:ja...@doe.com, jo...@doe.com"); // addresses where to send
i.extra("android.intent.extra.SUBJECT", entry().field("Subject")); // 2nd arg is what you want
i.extra("android.intent.extra.TEXT", entry().field("Body")); // 2nd arg is what you want
i.extra("android.intent.extra.ATTACHMENT", "storage/memento/files/myPhoto.jpg"); // THIS IS A GUESS!
i.send(); // send it out

Reference your Calculation field within the string you supply as the second argument to one of the i.extra() function calls. For instance:

i.extra("android.intent.extra.TEXT", "Prelude " + entry().field("myCalculation") + " Postlude");

See http://wiki.mementodatabase.com/index.php/Triggers.

Bill Crews

unread,
Dec 5, 2016, 5:29:05 AM12/5/16
to mementodatabase
Well, no one posted the attachment info, and you haven't posted back any results, so have you been able to send an email message from a trigger script?

I'm sure the ATTACHMENT "extra" line I guessed at is wrong. I didn't find the actual answer, but the Java-based examples I found suggested to me that maybe the right symbol, instead of ATTACHMENT, might be STREAM, but that's still a guess on my part.

After a few deadlines I'm working against are passed, I'll try to get it working myself, but in the meantime, could someone who knows please tell us how to code the attachment of a file (photo) to the email (code in previous post)? And could you, Horst, tell me if you got anything working?

Thanks in advance.

Bill Crews

unread,
Dec 5, 2016, 5:29:05 AM12/5/16
to mementodatabase

Horst Liebermann

unread,
Dec 18, 2016, 11:13:04 AM12/18/16
to mementodatabase
Creating and sending an email went very well.
Only problem of sending an attachment is still unsolved. I'm still searching how to send an Image or a PDF.
What I found is,that it's a problem of content definition. In Java the solution is available, bit I don't know how to set the information about the content type in the trigger. ( YouTube: "30 Android Intents Send Image from Drawable Folder).
Somebody has an idea?
Reply all
Reply to author
Forward
Message has been deleted
0 new messages