D
D
DR_Demons2016-01-23 13:45:39
Java
DR_Demons, 2016-01-23 13:45:39

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

the code
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(); }
but I get
exception
com.sun.mail.smtp.SMTPSendFailedException: 553 5.7.1 Sender address rejected: not owned by auth user.
how to fix it?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Max, 2016-01-23
@DR_Demons

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.

D
Dimonchik, 2016-01-23
@dimonchik2013

something like this:
https://forum.mozilla-russia.org/viewtopic.php?id=37132
spam protection
agree - for freemyl, which Yandex is - the ability to spam on behalf of another Yandex user is critical, the rest will look like and the original

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question