I am trying to send an e-mail using the Javamail, since it seems to be the only way to send an e-mail using SMTP.
I searched some posts like: Sending mail in android without intents using SMTP
But, I want a sender to be my own domain, not the gmail.
So I tried:
final String username = "admin@customsite.com";
final String password = "password";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.customsite.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("admin@customsite.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("username@gmail.com"));
message.setSubject("Hello there");
message.setText("This is a test email");
Transport.send(message);
Log.d("EmailClient", "Success");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
But it seems not to be working.