0
我正在寫一個android應用程序,假設在某些時候發送電子郵件。我在谷歌中創建了一個新的電子郵件帳戶。用戶名是:pickup .friend.carpool。這是我的郵件發送類:用Android應用程序發送郵件
public class MailSending {
private static String HOST = "smtp.gmail.com";
private static String USER = "[email protected]";
private static String PASSWORD = ""; //My password
private static String PORT = "465";
private static String FROM = "mail.com";
private static String TO;
private static String STARTTLS = "true";
private static String AUTH = "true";
private static String DEBUG = "true";
private static String SOCKET_FACTORY = "javax.net.ssl.SSLSocketFactory";
private static String SUBJECT;
private static String TEXT;
public void send(String to) {
TO = to;
SUBJECT = "subject";
TEXT = "body of mail";
Properties props = new Properties();
props.put("mail.smtp.host", HOST);
props.put("mail.smtp.port", PORT);
props.put("mail.smtp.user", USER);
props.put("mail.smtp.auth", AUTH);
props.put("mail.smtp.starttls.enable", STARTTLS);
props.put("mail.smtp.debug", DEBUG);
props.put("mail.smtp.socketFactory.port", PORT);
props.put("mail.smtp.socketFactory.class", SOCKET_FACTORY);
props.put("mail.smtp.socketFactory.fallback", "false");
try {
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
message.setText(TEXT);
message.setSubject(SUBJECT);
message.setFrom(new InternetAddress(FROM));
message.addRecipient(RecipientType.TO, new InternetAddress(TO));
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(HOST, USER, PASSWORD);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
這是我怎麼稱呼我的其他活動,這個類:
(new MailSending()).send("e-mail receiver");
每次程序進入郵件發送類它落在行,其中本寫成:message.saveChanges(); 在我的AndroidMainfest文件上,我只有互聯網權限。 也許我的AndroidMainfest文件有權限問題?還有什麼可能是這個問題?
我已經試過了。它沒有工作 – 2014-09-05 09:09:43