0

I am building an android app. I want to send an email from xxxxx@outlook.com. This is the code.

  public void setUp
      {
       Properties props = new Properties();
       props.setProperty("mail.transport.protocol", "smtp");
       props.put("mail.smtp.auth", "true");
       this.mailhost = "smtp.live.com";
       props.setProperty("mail.host", mailhost);
       props.put("mail.smtp.port", "587");
       props.setProperty("mail.smtp.starttls.enable", "true");
    }

I know that user should be the whole email address. But when I used I received an email that said I should start session before send a email.

This code worked 3 times and then stopped.

GrIsHu
  • 29,068
  • 10
  • 64
  • 102
nanoalvarez
  • 83
  • 2
  • 4
  • 10

2 Answers2

0

What does the debug output show? What was the exact error message? Exactly what did it say in the email you received? You may need to connect with POP3 or IMAP to read mail before it will let you send mail.

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40
0

You should get a session from Javamail, to create your message. Then, using a transport object, you can send it.

String host = "localhost";
int port = 443;
String user = "BruceWayne@example.org";
String password = "S3cr3tP4ss";
Session session = Session.getDefaultInstance(props);
session.setDebug(true);

Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(user, "Dark Knight"));
msg.setSubject("Hello Selina");
msg.setText("Do you want to have diner ?");
Transport transport = session.getTransport("smtp");
transport.connect(host, port, user, password);
transport.sendMessage(msg, msg.getAllRecipients());
gartcimore
  • 43
  • 9