I ask for help in handling the javax.mail class.

Written application for Android, which monitors the mailbox and sends responses. If I send a letter from one gmail box to another gmail box, then everything is OK. If the mail.ru mailbox, then send a letter does not work.

Mistake:

 E/MailApp: Could not send email 501 5.5.4 Invalid argument 

Here is the code:

 public class Mail extends javax.mail.Authenticator { public boolean send() throws Exception { Properties props = _setProperties(); Session session = Session.getDefaultInstance(props, this); MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(_from)); InternetAddress[] addressTo = new InternetAddress[_to.length]; for (int i = 0; i < _to.length; i++) { addressTo[i] = new InternetAddress(_to[i]); } msg.setRecipients(MimeMessage.RecipientType.TO, addressTo); msg.setSubject(_subject); msg.setSentDate(new Date()); // setup message body BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(_body); _multipart.addBodyPart(messageBodyPart); // Put parts in message msg.setContent(_multipart); // send email Log.d("Trying send", "host="+_host); Transport.send(msg); return true; } @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(_user, _pass); } private Properties _setProperties() { Properties props = new Properties(); props.put("mail.smtp.host", "smtp.mail.ru"); props.put("mail.debug", "true"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.user", "mymail@mail.ru"); 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; } } 

How to even know what exactly does not like the server?

I repeat, if I send a letter from the gmail box, everything works fine (of course, I’m changing the address of the smtp server)

Here is the SMTP log:

 I/System.out: DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.1] I/System.out: DEBUG SMTP: useEhlo true, useAuth true I/System.out: DEBUG SMTP: useEhlo true, useAuth true I/System.out: DEBUG SMTP: trying to connect to host "smtp.mail.ru", port 465, isSSL false D/dalvikvm: GC_FOR_ALLOC freed 533K, 6% free 10131K/10696K, paused 22ms, total 24ms I/System.out: DEBUG SMTP: connected to host "smtp.mail.ru", port: 465 E/MailApp: Could not send email 501 5.5.4 Invalid argument 
  • Try to reduce the sample code to the minimum . A small example showing a problem will attract more people who can help you. - Timofei Bondarev
  • Thanks for the tip, cut. - Danil
  • It was not possible to reproduce on the emulator, although in the current form the code requires revisions to run (it was at least compiled before "minification"). javax.mail-1.4.7. Tried to send and from the address with the included two-factor authentication, and without. The only thing that did not register the new box. Try to access the web interface of the mailbox you are sending from. Another javamail in debug mode writes to the console the entire dialogue with the server, you can see that the latter was sent to the server, before its response 501 . - zRrr
  • Yes, after "minimizing the code" it became non-compiled. ZRrr, did you have everything normally work with the mail.ru-box? Why go to the maul.ru box through the browser? Of course, I have access to it. Can something really change in the settings of the box? - Danil

1 answer 1

smtp.mail.ru, port 465, isSSL false

And if you try with isSSL = true or with port 25?