我有这个简单的代码与另一个jar库,使我能够发送电子邮件,而无需去其他邮件应用程序.
public class claimrewardemail extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.successful);
final String username = "myname@gmail.com";
final String password = "mypassword";
new Thread(new Runnable() {
@Override
public void run() {
try {
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 javax.mail.Authenticator() {
protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
return new javax.mail.PasswordAuthentication(
username, password);
}
});
// TODO Auto-generated method stub
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("from-email@gmail.com"));
message.setRecipients(Message.RecipientType.TO, …Run Code Online (Sandbox Code Playgroud)