Message: setRecipient(Message.RecipientType type, Address address) : Message « javax.mail « Java by API






Message: setRecipient(Message.RecipientType type, Address address)

 
import java.util.Properties;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Main {

  public static void main(String[] args) throws Exception {

    Properties props = new Properties();
    props.put("mail.host", "mail.cloud9.net");

    Session mailConnection = Session.getInstance(props, null);
    Message msg = new MimeMessage(mailConnection);

    Address a = new InternetAddress("a@a.com", "A a");
    Address b = new InternetAddress("fake@java2s.com");

    msg.setContent("Mail contect", "text/plain");
    msg.setFrom(a);
    msg.setRecipient(Message.RecipientType.TO, b);
    msg.setSubject("subject");

    Transport.send(msg);
  }
}

   
  








Related examples in the same category

1.Message.RecipientType.BCC
2.Message.RecipientType.CC
3.Message.RecipientType.TO
4.Message: getDisposition()
5.Message: getFrom()
6.Message: getLineCount()
7.Message: getReplyTo()
8.Message: getSize()
9.Message: setFrom(Address address)
10.Message: setSubject(String subject)