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
501. - zRrr