App Inventor Extensions


Mail Extension

See the App Inventor Extensions document about how to use an App Inventor Extension.

For questions about this extension or bug reports please start a new thread in the App Inventor community. Thank you.

For feature requests please contact me by email. To be a sponsor of a new method already is possible starting from only 10 USD! With your contribution you will help the complete App Inventor community. Thank you.

July 10th, 2016: Version 1 of the Mail Extension released (POP3 blocks are still experimental!)

Aug 11th, 2016: Version 1a: avoid DX execution failed error: build each extension separately

Dec 30th, 2016: Version 1b: simplification in send method, which fixes SSL issue, Base64Decode method added

Feb 14th, 2017: Version 1c: added permission android.permission.ACCESS_NETWORK_STATE to be able to send attachments via mobile internet

Jan 28th, 2019: Version 2: SDK 26 update: POP3 functionality removed, dangerous permission WRITE_EXTERNAL_STORAGE, which was used for POP3 removed. What is a dangerous permission?

Sep 7th, 2021: Version 3: SDK30 update: the issue Java mail crashing when sending email targeting Android 11 (SDK 30) is now fixed in the extension.

Nov 5th, 2023: Version 3a: new build because of DX error in case there are 2 extensions in a project which use progruard to obfuscate their sources.

Description

This extension enables you to send an email via SMTP. You can send to several To, Cc or Bcc addresses, add several attachments and send in plain text or HTML format. Note: SMTP authentication is set to true.

To use this extension together with Gmail accounts, you have to enable less secure apps in the Google settings, see also Why do I get AuthenticationFailedException when accessing Gmail?. See also Q10 below.

Required permissions: android.permission.INTERNET, android.permission.READ_EXTERNAL_STORAGE, android.permission.ACCESS_NETWORK_STATE
Minimum API: 19

Probably you want to read this first: What is SMTP?

This extension uses the Javamail API. Thank you Oracle!

Properties


Returns username.
Note: Formerly property username could be different compared to property From. Because of security reasons this seems to be not possible anymore for the most email providers.


Specifies username.


Returns password.


Specifies password.


Returns from (i.e. the email address of the sender of a message)


Specifies from (i.e. the email address of the sender of a message)..
Note: Formerly property username could be different compared to property From. Because of security reasons this seems to be not possible anymore for the most email providers.


Returns SMTP host.


Specifies SMTP host. Default value is smtp.gmail.com.


Returns SMTP port.


Specifies SMTP port. Default value is 465.


Returns whether text should be sent in HTML format.


Specifies whether text should be sent in HTML format. Default value is false.

Methods


Send email.
Subject and To address are mandatory. For To, Cc and Bcc you can add several addresses, use a comma as delimiter. Also you can add several attachments, use a comma as delimiter. You can't send attachments from the assets of the app.

Note: Ater the SDK30 release you can't access arbitrary directories anymore, which means, for attachments to your email to send, you are on the safe side if you add them from the ASD - application specific directory...

Events


Event indicating that email has been sent.
In case of success, the flag successful is true and the text "success" will be provided as response. In case of failure, the flag successful is false and an error message will be provided as response.

Example App: Mail Extension SMTP Test

Enter your settings and send emails to several To, Cc or Bcc addresses, add several attachments and send in plain text or HTML format to test the functionality of the Mail extension.

Screenshots:

SMTP - Questions and Answers

Q1: When I tried the .apk it gives as response javax.mail.AuthenticationFailedException 534-5.7.14?
A: To use this extension together with Gmail accounts, you have to enable less secure apps in the Google settings, see also Why do I get AuthenticationFailedException when accessing Gmail?.
Starting from 2022-05-30 Google does not allow less secure apps anymore. You have to sign in with App passwords now. Just use your gmail address together with the generated app password to use the mail extension with Gmail accounts. See also Q10 below.

Q2: Would you be able to assist me with the file location needed to send a different file in my test I am using ///storage/emulated/0/Folder/File.txt?
A: You can use a full path, which is file:///mnt/sdcard/Folder/File.txt or a relative path, which is /Folder/File.txt.

Q3: I have tried Mail Extension SMTP, it works with GMail, then I tried with another SMTP account (not GMail) and I received the following error message: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
A: It seems to be, your server is not correctly configured, see also this stackoverflow answer. Please contact your server administrator.

Q4: I have tried Mail Extension SMTP, it works with GMail, then I tried with another SMTP account (not GMail) and I received the following error message: javax.net.ssl.SSLHandshakeException: Handshake failed. We do not use any security settings. Can I disable SSL auth so I can use my SMTP server?
A: Please configure your server accordingly and use SSL, insecure methods are not supported by the extension.

Q5: You said that: you can add several attachments, use a comma as delimiter. You can't send attachments from the assets of the app. What do you mean exactly with "the assets of the app"?
A: Assets are all files, you uploaded as media into your project. To send a file from the assets, you first have to copy it to the internal sdcard and send it from there. To copy a file from the assets to the internal sdcard please use the file extension and its Copy method.

Q6: I'm using a Gmail account to send emails and some user get an error message and the message will not be sent?
A: The restrictive security mechanisms of the Google account might prevent sending the emails. For each access to the Gmail account Google is checking the location of the user and tries to find out, if it's you who is sending the email. It might be, that Google is assuming, that someone else found out your password and therefore refrains from sending the email. You might want to use an email provider with less restrictive security settings....

Q7: I'm trying to use the extension with Office365 mail, which uses port 587 and STARTTLS and I received the following error message: com.sun.mail.util.MailConnectException: Could not connect to host, port: smtp.outlook365.com, 587; timeout -1; nested exception is: java.net.UnknownHostException: smtp.outlook365.com
A: Thank you for your test. It seems to be, the extension does not work together with port 587 and STARTTLS. I will put this onto my to do list and probably will add this feature one day. Thank you again.

Q8: YA FUI A LA CUENTA DE GMAIL Y HABILITE COMO APLICACION MENOS SEGURAS, COMO VERAS EN LA IMAGEN, PUSE EL CORREO Y EN NOMBRE DE USUARIO Q FIGURO EN GMAIL Y EL PASSWORD Q USO PARA ENTRAR A MI CORREO.- NO SE Q NOMBRE DE USUAIRO O PASSWORD ME PIDE.- EN LA OTRA IMAGEN ESTA EL ERROR Q ME SALE EN LA APP.- HAY ALGUN VIDEO Q MUESTRE BIEN COMO SE HACE APARTE DE LO Q FIGURA EN LA PAGINA DE PURA VISTA? PERDON POR LA MOLESTIA PERO NECESITO ESTO SI O SI.-
A: Dear Fernando, especially for you I now prepared a very simple example project, which you now also can find in the download folder to download. I recommend you to do the tutorials to learn the basics, see also here.
And btw. it seems to be, you still don't understand, how you are perceived with CAPS LOCK...
Please no CAPS LOCK next time. Thank you.




Q9: I try to use AOL mail and I received the following error message: javax.mail.Authentication.FailedException: 535 5.7.0 (#AUTH005) Too many bad auth attempts when trying to send email. Does it not work with AOL?
A: See this solution.
Feedback: I ended up using Yahoo mail and using the app generated password to log into my email account, see also here. The same way works for aol mail.

Q10: I try to use Gmail and I received the following error message: javax.mail.AuthenticationFailedException: 534-5.7.9 Application-specific password required when trying to send email. What can I do?
A: See this Stackoverflow answer: You have enabled Two phase authentication for your Google account and as a result applications will not be able to login to your Google account using the actual password. Google expects you to generate a application specific password for each application you use (and give it a name) and then use that password to login to your Google account from your application. This allows you to not give your password to third party application when you have 2-step authentication enabled. See here what to do.

For questions about App Inventor,
please ask in the App Inventor community.Thank you.

Test the functionality of the Mail extension

The SMTP test app is available in Google Play. You can test the example following these steps

  1. Follow the opt-in URL to get access to the app and to be able to download it to your device. It might take a few hours for Google to enable you as beta tester!
  2. Start testing.

Buy the Mail extension for App Inventor


You can buy this extension (aix file).
With your payment you accept the terms and conditions below.

Payment options

1. Paypal

Please transfer 12 USD via Paypal
to Pura Vida Apps

2. Bitcoin

After having received your payment I will be happy to send the download link to you. Please let me know your Google account! I usually will send the download link not later than 24 hours after having received your payment.
Thank you! Taifun


Terms and Conditions

Back to top of page ...


Home | Snippets | Tutorials | Extensions | Links | Search | Privacy Policy | Contact