Answer the question
In order to leave comments, you need to log in
How to send messages via smtp yandex?
Good day! The problem is the following, you need to send letters from the mailbox, it is located on yandex, I try this
String to = "[email protected]"; // sender email
String from = "[email protected]"; // receiver email
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", "smtp.yandex.ru");
properties.setProperty("mail.smtp.port", "465");
properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.setProperty("mail.smtp.socketFactory.port", "465");
properties.setProperty("mail.smtp.auth", "true");
Session session = Session.getInstance(properties,new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("[email protected]","senderPasswd");
}
}); // default session
try {
MimeMessage message = new MimeMessage(session); // email message
message.setFrom(new InternetAddress(from)); // setting header fields
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Test Mail from Java Program"); // subject line
// actual mail body
message.setText("Some Message");
// Send message
Transport.send(message); System.out.println("Email Sent successfully....");
} catch (MessagingException mex){ mex.printStackTrace(); }
com.sun.mail.smtp.SMTPSendFailedException: 553 5.7.1 Sender address rejected: not owned by auth user.
Answer the question
In order to leave comments, you need to log in
So, it seems that I understand what the problem is:
javatalks.ru/topics/17071?page=1#81943
Here they write that Yandex does not allow FROM, but they say that the solution "SMTPMessage.setEnvelopeFrom will not help? SMTP perfectly allows you to replace all this. "
If there is a code, so to speak, the original one, then replace the login-password and mail.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question