My sendEmail()
function works in Eclipse with straight Java and I can send emails without any issue, but once I plug the function into my Android application none of the emails are being sent. I have added the javax.mail
and javax.activation
JARs to my build path in both cases. Here is the code for the function and then the LogCat reading. On a button click sendEmailCustomer()
is called and nothing occurs. Any suggestions are more than appreciated.
public void sendEmailCustomer() {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.stmp.user", "user");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
String username = "user";
String password = "password";
return new PasswordAuthentication(username, password);
}
});
EditText e = (EditText) findViewById(R.id.enterEmail);
String to = e.toString();
String from = "user";
String subject = "Testing...";
MimeMessage msg = new MimeMessage(session);
try {
msg.setFrom(new InternetAddress(from));
msg.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(
to));
msg.setSubject(subject);
msg.setText("Did you get this?");
Transport transport = session.getTransport("smtp");
transport.send(msg);
} catch (Exception exc) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(exc.toString());
builder.setTitle("Error!");
builder.setNeutralButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
}
}
Updated LogCat errors. It sounds like the application cannot access the internet even though it has permission in my manifest. Why is this?
04-03 12:38:07.166: W/IInputConnectionWrapper(2528): showStatusIcon on inactive InputConnection
04-03 12:38:07.166: W/IInputConnectionWrapper(2528): InputConnection =
com.android.internal.widget.EditableInputConnection@411c5f28, active client = false