我正在使用JavaEmail API发送电子邮件但遇到问题。
我收到以下错误。
04-17 21:10:09.470: E/AndroidRuntime(28920): java.lang.NoClassDefFoundError: nz.co.devicelocation.EmailSender$1
这是我的SendEmail类,
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import android.util.Log;
public class EmailSender {
private static final String FROM = "location@gmail.com";
private static final String LOGIN = "location@gmail.com";
private static final String PASSWORD = "passthrough";
private static final String SUBJECT = "Your android device Location";
public EmailSender(String val){
Log.d("EmailSender", "inside constructor of emailsender");
}
public void sendEmail(){
Log.d("EmailSender", "Email Sent!@@@@@@@@@@");
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new Authenticator() { <<<<<<<-------------Error is happening here
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(LOGIN, PASSWORD);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(FROM));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("testemailrun@gmail.com"));
message.setSubject(SUBJECT);
message.setText("Testing from android");
Transport.send(message);
Log.d("EmailSender", "EmailSent");
} catch (MessagingException e) {
//If any exception is thrown user is warned.
Log.d("EmailSender", e.getMessage());
}
}
我似乎在以下代码中收到错误
Session session = Session.getInstance(props,
new Authenticator() { <<<<<<<-------------Error is happening here
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(LOGIN, PASSWORD);
}
});
我已经将mail.jar添加到我的库中,但验证者仍然会抛出错误。
有什么遗漏吗?