MailSender

public class MailSender extends MailConnector

MailSender is a mail connector for making connections to outgoing mail servers.

Author:Hugo Y. K. Lam

Constructors

MailSender

public MailSender(String host)

Creates a new instance of MailSender. The default protocol is SMTP.

Parameters:
  • host – the mail host.

MailSender

public MailSender(String host, String username, String password)

Creates a new instance of MailSender. The default protocol is SMTP.

Parameters:
  • host – the mail host.
  • username – the user name for authentication.
  • password – the password for authentication.

MailSender

public MailSender(String protocol, String host)

Creates a new instance of MailSender.

Parameters:
  • protocol – the mail protocol.
  • host – the mail host.

MailSender

public MailSender(String protocol, String host, String username, String password)

Creates a new instance of MailSender.

Parameters:
  • protocol – the mail protocol.
  • host – the mail host.
  • username – the user name for authentication.
  • password – the password for authentication.

Methods

createMessage

public MimeMessage createMessage()

Creates a MIME message from the underlying mail properties.

Returns:a new MIME message.

createMessage

public MimeMessage createMessage(Session session)

Creates a MIME message from the given mail session.

Parameters:
  • session – the mail session.
Returns:

a new MIME message.

createMessage

public MimeMessage createMessage(String from, String to, String cc, String subject)

Creates a simple MIME message with some basic headers.

Parameters:
  • from – the ‘from’ mail address.
  • to – the ‘to’ mail address(es).
  • cc – the ‘cc’ mail address(es).
  • subject – the mail subject.
Throws:
Returns:

a new MIME message.

createMessage

public MimeMessage createMessage(String from, String to, String cc, String subject, Session session)

Creates a simple MIME message with some basic headers.

Parameters:
  • from – the ‘from’ mail address.
  • to – the ‘to’ mail address(es).
  • cc – the ‘cc’ mail address(es).
  • subject – the mail subject.
  • session – the mail session.
Throws:
Returns:

a new MIME message.

send

public void send(String from, String to, String cc, String subject, String body)

Sends a simple mail message.

Parameters:
  • from – the ‘from’ mail address.
  • to – the ‘to’ mail address(es).
  • cc – the ‘cc’ mail address(es).
  • subject – the mail subject.
  • body – the message content.
Throws:

send

public void send(Message msg)

Sends a mail message.

Parameters:
  • msg – the mail message to be sent.
Throws: