3
    MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("[email protected]"));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));

Getting error in last two lines that unhandled exception type MessagingException.

Eclipse suggests me to cover them with a try catch block.But when i tried to search in internet they are using these two statement without any try catch block. so i think i am doing something wrong. how to solve this?

3

1 Answer 1

1

You have to possibilities to solve it.

  1. Add a try-catch- block arround your code:

    try { MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress("[email protected]")); msg.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));

    } catch (MessagingException me){ // do something }

  2. Add throws MessagingException to the method signature:

    public void mymethod throws MessagingException { MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress("[email protected]")); msg.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]")); }

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.