suneth rajamanthri
suneth rajamanthri

Reputation: 75

Android send email from any Email Address programmatically

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.

Upvotes: 5

Views: 4131

Answers (1)

Jhanvi
Jhanvi

Reputation: 5139

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.

Upvotes: 6

Related Questions