Question

I have App engine Application.

I have one servlet named push. I deploy me application and call my servlets GET method.

In My servlet, I have two methind:

1) first is that: (that method does not send mails. I dont undestand why? I have no errors)

void sendMail() throws UnsupportedEncodingException{

        Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);
        String msgBody = "TEXT HERE";
        try {
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress("ownerMail","Example.com Admin"));
            msg.addRecipient(Message.RecipientType.TO, new InternetAddress("maria.chiamaia@gmail.com", "Mr. User"));
            msg.setSubject("YOUR PDF HAVE PROBLEMS");
            msg.setText(msgBody);

        } catch (AddressException e) {
            log("error", e);
        } catch (MessagingException e) {
            log("error", e);
        }

}

and I call another method too: (this works!)

void snedTest(){

String to = "somebody";
String from = "ownerMail";
String host = "localhost:8080";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);

try {

    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject("This is the Subject Line!");
    message.setText("This is actual message");
    Transport.send(message);
    System.out.println("Sent message successfully....");
} catch (MessagingException mex) {
    mex.printStackTrace();
}

}

first method does not work! I don't know why? I have no error in LOG. But the second method works.

Was it helpful?

Solution

OH, I did not have

 Transport.send(message);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top