試試這個片段改變你的SMTP服務器。 雅虎: 發送郵件服務器(SMTP):plus.smtp.mail.yahoo.com 使用SSL,端口:465,使用身份驗證。
段:
Properties props = new Properties();
props.put("mail.smtp.user", myEmail);
props.put("mail.smtp.host", smptServer);
props.put("mail.smtp.port", port);
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.socketFactory.port", port);
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
SecurityManager security = System.getSecurityManager();
try {
Authenticator auth = new autentificadorSMTP();
Session session = Session.getInstance(props, auth);
// session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setText(body);
msg.setSubject(subject);
msg.setFrom(new InternetAddress(myEmail));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
toEmail));
Transport.send(msg);
} catch (Exception mex) {
mex.printStackTrace();
}
的Util:
private class authSMTP extends javax.mail.Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(myEmail, myPass);
}
}
希望它能幫助!
希望你能從這裏得到你的答案:http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in- a –
我這樣做了,但我想發送郵件到其他域,如我在上面的查詢中提到@ shree202 –
我不明白。您只需更改「至」電子郵件地址。什麼是真正的問題? – Simon