5

I am writing an app to send email programmatically without using Intent.

I was able to write the app using Java Mail API using SMTP with Gmail Authentication.

But this application supports to send email using only gmail Addresses. Using any Gmail address and password, I can send the email to any email address as well.

private Properties _setProperties() { 
    Properties props = new Properties(); 


props.put("mail.smtp.host", "smtp.gmail.com"); 

if(_debuggable) { 
  props.put("mail.debug", "true"); 
} 

if(_auth) { 
  props.put("mail.smtp.auth", "true"); 
} 

props.put("mail.smtp.port", _"465"); 
props.put("mail.smtp.socketFactory.port", _"465"); 
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); 
props.put("mail.smtp.socketFactory.fallback", "false"); 


    return props; 
  } 

But I want to use Any email address with Password Other than gmail and send the Email like Yahoo, etc. When I try with Yahoo, the Mail was not sent.

Please advice me to how to achieve this task.

Thank you in Advance.

m59
  • 43,214
  • 14
  • 119
  • 136
  • Does any one knows how to send emails programmatically from any email address in Android? Please Help me to handle this app... – suneth rajamanthri Dec 13 '13 at 05:10
  • Please write the code u tried.. – Jhanvi Dec 13 '13 at 10:13
  • jHanvi: I have attached code which used to send the email. From this i was able to send From Gmail Addess only. But i want to send from yahoo, Hotmail etc. – suneth rajamanthri Dec 13 '13 at 11:29
  • Please check below link http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in-a/2033124#2033124 It might help you – sachin pareek Mar 25 '14 at 05:10

1 Answers1

6

Port and host are variables, which vary for different providers. Example:

Gmail- Host: smtp.gmail.com , Port: 465

Hotmail- Host: smtp.live.com , Port: 587

Yahoo- Host: smtp.mail.yahoo.com , Port: 465

Change these values according to the provider you are using and it will be done.

Jhanvi
  • 5,069
  • 8
  • 32
  • 41
  • What could I give for outlook.com? I tried `smtp-mail.outlook.com` as Host and `587` as Port but it's not working. – Shailendra Madda Jun 07 '21 at 10:50
  • Getting this exception: `javax.mail.MessagingException: Could not connect to SMTP host: smtp-mail.outlook.com, port: 587; nested exception is: javax.net.ssl.SSLException: Unable to parse TLS packet header` – Shailendra Madda Jun 07 '21 at 11:04