當前位置: 首頁>>代碼示例>>Java>>正文


Java MimeMessage.addRecipients方法代碼示例

本文整理匯總了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);
}
 
開發者ID:hotpads,項目名稱:datarouter,代碼行數:18,代碼來源:DatarouterEmailTool.java

示例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;
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:37,代碼來源:MailService.java

示例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();
	}
}
 
開發者ID:zylo117,項目名稱:SpotSpotter,代碼行數:57,代碼來源:Mail_POP3.java

示例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);
  }
}
 
開發者ID:chickling,項目名稱:kmanager,代碼行數:45,代碼來源:EmailSender.java


注:本文中的javax.mail.internet.MimeMessage.addRecipients方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。