I need to send an email using client settings. Access to the host uses STARTTLS security using port 587. To test rode the following code (changed customer data for security):
String host = "zimbra.mydomain.net.br";
String port = "587";
String address = "[email protected]";
String pass = "******";
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.quitwait", "false");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", address);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", port);
props.put("mail.smtp.ssl.trust", "*");
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(address));
Multipart multiPart=new MimeMultipart();
InternetAddress toAddress = new InternetAddress("[email protected]");
message.addRecipient(Message.RecipientType.TO, toAddress);
message.setSubject("Send Auto-Mail");
message.setContent(multiPart);
message.setText("Demo For Sending Mail in Android Automatically");
Transport transport = session.getTransport("smtp");
transport.connect(host, address, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
Exception:
javax.mail.SendFailedException: Invalid Addresses; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 unknown[000.000.000.00]: Client host rejected: Access denied
-- EDIT --
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.1] DEBUG SMTP: useEhlo true, useAuth false DEBUG SMTP: trying to connect to host "zimbra.myclientaddress.net.br", port 587, isSSL false 220 zimbra.myclientaddress.net.br ESMTP Postfix DEBUG SMTP: connected to host "zimbra.myclientaddress.net.br", port: 587 EHLO localhost
250-zimbra.myclientaddress.net.br
250-PIPELINING
250-SIZE 1741203456
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "1741203456"
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:
250 2.1.0 Ok
RCPT TO:
554 5.7.1 : Client host rejected: Access denied
DEBUG SMTP: Invalid Addresses
DEBUG SMTP: [email protected]
DEBUG SMTP: Sending failed because of invalid destination addresses
RSET
250 2.0.0 Ok