我正在开发一个使用jar库发送电子邮件的应用程序。我正在使用自定义电子邮件帐户从android应用发送电子邮件。以下是发件人活动的代码
private String mailhost = "us2.smtp.mailhostbox.com";
public GMailSender(String user, String password) {
this.user = user;
this.password = password;
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", mailhost);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.socketFactory.port", "587");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.quitwait", "false");
session = Session.getDefaultInstance(props, this);
}
以下代码用于设置发件人和收件人
final ProgressDialog pd = ProgressDialog.show(MessageActivity.this,"Sending...", "Please Wait...",true);
new Thread(new Runnable() {
public void run() {
try {
GMailSender sender = new GMailSender("apps@softglobe.net", "XXXXXX");
//sender.addAttachment(Environment.getExternalStorageDirectory().getPath()+"/image.jpg");
sender.sendMail("New Message from Arsod Classes App", "New Message from Arsod Classes App\nName: " + nm + "\nEmail: " + em + "\nMessage: " + msg,
"apps@softglobe.net", "softglobe.technologies@gmail.com");
MessageActivity.this.runOnUiThread(new Runnable() {
public void run() {
pd.dismiss();
Toast.makeText(getApplicationContext(), "Mail Sent successfully!", Toast.LENGTH_LONG).show();
}
});
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG).show();
}
}
}).start();
当我尝试使用上述代码发送电子邮件时,出现Toast
并说“电子邮件已发送”,但是我没有在收件人那边收到。
同样,当我尝试使用php
网站和phpmailer
库发送具有相同凭据的电子邮件时,则电子邮件发送成功。可能是什么问题?请帮忙。我花了很多时间,但没有找到任何解决方案。我正在使用Google提供的jar库,分别为activation.jar
,additional.jar
和mail.jar
。