Setting up sending mail via smtp.
private String mailhost = "smtp.yandex.ru";
private String user;
private String password;
private Session session;
public static final String TAG = "GMailSender: ";
static {
Security.addProvider(new JSSEProvider());
}
public GMailSender(String user, String password) {
this.user = user;
this.password = password;
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", mailhost);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.quitwait", "false");
session = Session.getDefaultInstance(props, this);
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
I do it according to this instruction https://yandex.ru/support/mail/mail-clients/others.html. a password from passwords for applications. But I get the error Error sending mail com. sun. mail. smtp. SMTPSendFailedException:553 5.7.1 Sender address rejected: does not belong to the auth user.