📄 mailer.java
字号:
/*
* @author : Neelesh
* @Version : 2.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the File : Mailer.java
* Creation/Modification History :
*
* Neelesh 02-March-2003 Created
*
*/
package oracle.otnsamples.util;
import javax.mail.Message;
// JavaMail APIs
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
* This class is implemented as an e-mail client utility to send mails based on
* the mail parameters.
*
* @author Neelesh
* @version 2.0
*/
public final class Mailer {
/**
* This method sends the e-mail based on the mail parameters.
*
* @param <b>mail</b> This object has details regarding the mail to be sent
*
* @throws <b>UtilityException</b> if any error in sending the mail
*/
public static void sendMail(MailContent mail) throws UtilityException {
try {
// Get the default mails session using the message
// properties like smtp host.
Session session =
Session.getDefaultInstance(Utilities.loadParams("Message"), null);
// Create a new message
Message msg = new MimeMessage(session);
// Set the 'from' address
msg.setFrom(new InternetAddress(mail.getFrom()));
// Set the 'to' address (es)
msg.setRecipient(
Message.RecipientType.TO,
new InternetAddress(mail.getTo()));
// Set 'cc' list
String[] ccList = mail.getCC();
if(ccList != null) {
for(int i = ccList.length - 1; i >= 0; i--) {
msg.addRecipient(
Message.RecipientType.CC,
new InternetAddress(ccList [ i ]));
}
}
// Set the 'subject' of the mail
msg.setSubject(mail.getSubject());
// Set the message of the mail
msg.setText(mail.getBody());
// Send the message
Transport.send(msg);
} catch(Exception ex) {
throw new UtilityException("Unable to send the mail from sendMail " +
"method of Mailer class : " + ex.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -