本文整理匯總了Java中javax.mail.internet.MimeMessage.addRecipients方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeMessage.addRecipients方法的具體用法?Java MimeMessage.addRecipients怎麽用?Java MimeMessage.addRecipients使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.mail.internet.MimeMessage
的用法示例。
在下文中一共展示了MimeMessage.addRecipients方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendEmail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private static void sendEmail(String fromEmail, String toEmail, String subject, String body, boolean html)
throws MessagingException{
MimeMessage message = new MimeMessage(MAILING_SESSION);
message.setFrom(new InternetAddress(fromEmail));
InternetAddress[] addresses = InternetAddress.parse(toEmail);//one or more addresses
message.addRecipients(RecipientType.TO, addresses);
message.setReplyTo(addresses);
message.setSubject(subject);
String subType;
if(html){
subType = "html";
}else{
subType = "plain";
}
message.setText(body, "UTF-8", subType);
Transport.send(message);
}
示例2: convert2JavaMailMsg
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* Converts the specified message into a {@link javax.mail.Message
* javax.mail.Message}.
*
* @param message
* the specified message
* @return a {@link javax.mail.internet.MimeMessage}
* @throws Exception
* if converts error
*/
public javax.mail.Message convert2JavaMailMsg(final MailMessage message) throws Exception {
if (message == null) {
return null;
}
if (StringUtils.isBlank(message.getFrom())) {
throw new MessagingException("Null from");
}
if (null == message.getRecipients() || message.getRecipients().isEmpty()) {
throw new MessagingException("Null recipients");
}
final MimeMessage ret = new MimeMessage(getSession());
ret.setFrom(new InternetAddress(message.getFrom()));
final String subject = message.getSubject();
ret.setSubject(MimeUtility.encodeText(subject != null ? subject : "", "UTF-8", "B"));
final String htmlBody = message.getHtmlBody();
ret.setContent(htmlBody != null ? htmlBody : "", "text/html;charset=UTF-8");
ret.addRecipients(javax.mail.Message.RecipientType.TO, transformRecipients(message.getRecipients()));
return ret;
}
示例3: main
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public static void main(String[] args) {
try {
final String host = "smtp.qq.com";// ����QQ�����smtp��������ַ
final String port = "25"; // �˿ں�
/*
* Properties��һ�����Զ�����������Session����
*/
final Properties props = new Properties();
props.setProperty("mail.smtp.host", host);
props.setProperty("mail.smtp.port", port);
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.smtp.ssl.enable", "false");// "true"
props.setProperty("mail.smtp.connectiontimeout", "5000");
final String user = "******@qq.com";// �û���
final String pwd = "******";// ����
/*
* Session�ඨ����һ���������ʼ��Ի���
*/
final Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
// ��¼�û�������
return new PasswordAuthentication(user, pwd);
}
});
session.setDebug(true);
/*
* Transport�����������ʼ��� �������smtp��transport���Զ�����smtpЭ�鷢���ʼ���
*/
final Transport transport = session.getTransport("smtp");// "smtps"
transport.connect(host, user, pwd);
/*
* Message������������ʵ�ʷ��͵ĵ����ʼ���Ϣ
*/
final MimeMessage message = new MimeMessage(session);
message.setSubject("�ʼ�����");
// ��Ϣ�����߽���������(������ַ���dz�)���ռ��˿������dz��������趨��
message.setFrom(new InternetAddress(user, "��ʦ��"));
message.addRecipients(Message.RecipientType.TO, new InternetAddress[] {
// ��Ϣ������(�ռ���ַ���dz�)
// ��������dz�ò��û�п���Ч��
new InternetAddress("[email protected]", "��ʦ��"), });
message.saveChanges();
// �����ʼ����ݼ������ʽ
// ��һ���������Բ�ָ�����룬��"text/plain"�����ǽ�������ʾ�����ַ�
message.setContent("�ʼ�����..", "text/plain;charset=UTF-8");
// ����
// transport.send(message);
Transport.send(message);
transport.close();
} catch (final Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例4: sendEmail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public static void sendEmail(String message, String sendTo, String group_topic) {
Properties properties = System.getProperties();
if (config.getSmtpAuth()) {
properties.setProperty("mail.user", config.getSmtpUser());
properties.setProperty("mail.password", config.getSmtpPasswd());
}
properties.setProperty("mail.smtp.host", config.getSmtpServer());
Session session = Session.getDefaultInstance(properties);
MimeMessage mimeMessage = new MimeMessage(session);
try {
String[] sendToArr = sendTo.split(";");
mimeMessage.setFrom(new InternetAddress(config.getMailSender()));
if (sendToArr.length > 1) {
String cc = "";
for (int i = 1; i < sendToArr.length; i++) {
cc += i == sendToArr.length - 1 ? sendToArr[i] : sendToArr[i] + ",";
}
mimeMessage.addRecipients(Message.RecipientType.CC, InternetAddress.parse(cc));
}
mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(sendToArr[0]));
String[] group_topicArr = group_topic.split("_");
String subject = config.getMailSubject();
if (subject.contains("{group}")) {
subject = subject.replace("{group}", group_topicArr[0]);
}
if (subject.contains("{topic}")) {
subject = subject.replace("{topic}", group_topicArr[1]);
}
mimeMessage.setSubject(subject);
mimeMessage.setSentDate(new Date());
mimeMessage.setContent(message, "text/html");
Transport.send(mimeMessage);
} catch (
Exception e) {
LOG.error("sendEmail faild!", e);
}
}