Send email with attachments

If you are new to SL4A and scripting, take a look at this wiki entry about using SL4A with Tasker.

This Python script allows you to send an email, optionally with one or more attachments, without the "compose" step.

The script takes the following parameters:

Parameter Required? Description
%EMAIL_NAME No Your name (goes into the return address)
%EMAIL_USER Yes Your gmail user ID, excluding the part
%EMAIL_PSWD Yes Your gmail password
%EMAIL_TO Yes The address to which to send the email, e.g., moc.liame|htimsj#moc.liame|htimsj
%EMAIL_SUBJECT No The email subject
%EMAIL_BODY No The text of the email message
%EMAIL_ATTACH No A comma-separated list of files to be attached. The filenames have to be fully qualified, e.g., /sdcard/file.txt. Wildcards OK. See this link for a full explanation of how the wildcards work.

To run the script, create a Task (Misc / Run Script) to run, and include the parameters you need in a comma separated list in the "Pass Variables" section. You may either omit the optional parameters or include them in an "un-set" condition. I suggest that you create a sendemail task that passes all the parameters, then, in a separate task, set the variables you need, and un-set the ones you don't, and call the sendemail task.

Task: sendemail

  • The script stands on its own without reference to other data or applications. It does not depend on or try to use other email clients or accounts you may already have set up on your phone. It doesn't know about those other accounts, nor does it care what they are.
  • It depends on the user passing it parameters containing valid user id and password for a gmail account.
  • It doesn't allow you to send email FROM non-gmail accounts in it current incarnation.
  • It does, of course, allow you to send email TO any other valid email address, not just gmail addresses.

I'll monitor this thread for questions.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License