6
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
private void sendMail() throws MessagingException{
String host = "smtp.gmail.com";
String password = "abcde12345";
String from = "[email protected]";
String toAddress = email;
String filename = Environment.getExternalStorageDirectory() + "/jam.jpg";
Properties properties = System.getProperties();
properties.put("mail.smtp.host", host);
properties.put("mail.smtps.auth", true);
properties.put("mail.smtp.starttls.enable", true);
Session session = Session.getInstance(properties, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, toAddress);
message.setSubject("Anti-Theft Attachment");
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(smsMessageString);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
try{
Transport transport = session.getTransport("smtps");
transport.connect(host, from, password);
transport.sendMessage(message, message.getAllRecipients());
System.out.println("Mail Sent Successfully");
transport.close();
} catch (SendFailedException sfe){
System.out.println(sfe);
}
};
我開發的應用程序,一旦手機被盜或丟失的應用程序會自動發送一封電子郵件給用戶,告知用戶當前手機的狀態。但是我在導入javax.mail時遇到問題「導入的javax.mail無法解析」。我該怎麼辦?謝謝...進口javax.mail不能得到解決
http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in-a – dira
ADD 3 jars found in the following鏈接到您的Android項目。 http://stackoverflow.com/a/2033124/375953 – dira
感謝您的幫助:) –