当前位置: 首页>>代码示例>>Java>>正文


Java MimeMessage.setRecipients方法代码示例

本文整理汇总了Java中javax.mail.internet.MimeMessage.setRecipients方法的典型用法代码示例。如果您正苦于以下问题:Java MimeMessage.setRecipients方法的具体用法?Java MimeMessage.setRecipients怎么用?Java MimeMessage.setRecipients使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.mail.internet.MimeMessage的用法示例。


在下文中一共展示了MimeMessage.setRecipients方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSimpleMail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
  * @Method: createSimpleMail
  * @Description: ����һ��ֻ�����ı����ݵ��ʼ�
  * @param session
  * @return
  * @throws Exception
  */ 
  public static MimeMessage createSimpleMail(String subject, String content) throws Exception {
  	
      //�����ʼ�����
      MimeMessage message = new MimeMessage(session);
      //ָ���ʼ��ķ�����
      message.setFrom(new InternetAddress(username));
      if(recipients.contains(";")){
	List<InternetAddress> list = new ArrayList<InternetAddress>();
	String []median=recipients.split(";");
	for(int i=0;i<median.length;i++){
		list.add(new InternetAddress(median[i]));
	}
	InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
	message.setRecipients(Message.RecipientType.TO,address);
}else{
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
      //�ʼ��ı���
      message.setSubject(subject);
      //�ʼ����ı�����
      message.setContent(content, "text/html;charset=UTF-8");
      //���ش����õ��ʼ�����
      return message;
  }
 
开发者ID:AlanYangs,项目名称:Log4Reports,代码行数:32,代码来源:EmailUtil.java

示例2: sendEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
@Override
public void sendEmail(String address, String subject, String content, Map<String, String> headers) throws Exception {
	Session session = MailUtilities.makeSession();
	if (session == null) {
		// LogService.getRoot().warning("Unable to create mail session. Not sending mail to "+address+".");
		LogService.getRoot().log(Level.WARNING, "com.rapidminer.tools.MailSenderSMTP.creating_mail_session_error",
				address);
	}
	MimeMessage msg = new MimeMessage(session);
	msg.setRecipients(Message.RecipientType.TO, address);
	msg.setFrom();
	msg.setSubject(subject, "UTF-8");
	msg.setSentDate(new Date());
	msg.setText(content, "UTF-8");

	if (headers != null) {
		for (Entry<String, String> header : headers.entrySet()) {
			msg.setHeader(header.getKey(), header.getValue());
		}
	}
	Transport.send(msg);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:23,代码来源:MailSenderSMTP.java

示例3: process

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
@Override
public String process() {
	logger.info("Running inside MailBatchlet batchlet ");
	String fromAddress = stepContext.getProperties().getProperty("mail.from");
	String toAddress = stepContext.getProperties().getProperty("mail.to");

	try {
		MimeMessage m = new MimeMessage(mailSession);
		Address from = new InternetAddress(fromAddress);
		Address[] to = new InternetAddress[] { new InternetAddress(toAddress) };

		m.setFrom(from);
		m.setRecipients(TO, to);
		m.setSubject("Batch on wildfly executed");
		m.setSentDate(new java.util.Date());
		m.setContent("Job Execution id " + jobContext.getExecutionId() + " warned disk space getting low!",
				"text/plain");
		send(m);

	} catch (javax.mail.MessagingException e) {
		logger.log(SEVERE, "error send mail", e);

	}
	return COMPLETED.name();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:26,代码来源:MailBatchlet.java

示例4: sendHtmlEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public void sendHtmlEmail(EmailObject email) throws Exception {
    // 创建Session实例对象
    Session session = Session.getInstance(props, new EmailAuthenticator());

    // 创建MimeMessage实例对象
    MimeMessage message = new MimeMessage(session);
    // 设置邮件主题
    message.setSubject(email.getEmailSubject(),"utf-8");
    // 设置发送人
    message.setFrom(new InternetAddress(from));
    // 设置发送时间
    message.setSentDate(new Date());
    // 设置收件人
    message.setRecipients(MimeMessage.RecipientType.TO, InternetAddress.parse(email.getToEmail()));
    // 设置html内容为邮件正文,指定MIME类型为text/html类型,并指定字符编码为gbk
    message.setContent(email.getEmailContent(), "text/html;charset=utf-8");
    // 保存并生成最终的邮件内容
    message.saveChanges();
    // 发送邮件
    Transport.send(message);
    //记录邮件发送日志
    SendEmailLog sendEmailLog = new SendEmailLog();
    sendEmailLog.setToemail(email.getToEmail());
    sendEmailLog.setSubject(email.getEmailSubject());
    sendEmailLog.setSenddate(new Date());
    sendEmailLog.setContent(email.getEmailContent());
    sendEmailLogDao.insert(sendEmailLog);
}
 
开发者ID:NeilRen,项目名称:NEILREN4J,代码行数:29,代码来源:EmailUtils.java

示例5: send

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
@Override
public void send(String senderAddress, String senderName, String recipient, String content) {
    if (StringUtils.isBlank(senderAddress)) {
        throw new FeatureNotAvailable("3PID Email identity: sender address is empty - " +
                "You must set a value for notifications to work");
    }

    if (StringUtils.isBlank(content)) {
        throw new InternalServerError("Notification content is empty");
    }

    try {
        InternetAddress sender = new InternetAddress(senderAddress, senderName);
        MimeMessage msg = new MimeMessage(session, IOUtils.toInputStream(content, StandardCharsets.UTF_8));
        msg.setHeader("X-Mailer", "mxisd"); // FIXME set version
        msg.setSentDate(new Date());
        msg.setFrom(sender);
        msg.setRecipients(Message.RecipientType.TO, recipient);
        msg.saveChanges();

        log.info("Sending invite to {} via SMTP using {}:{}", recipient, cfg.getHost(), cfg.getPort());
        SMTPTransport transport = (SMTPTransport) session.getTransport("smtp");
        transport.setStartTLS(cfg.getTls() > 0);
        transport.setRequireStartTLS(cfg.getTls() > 1);

        log.info("Connecting to {}:{}", cfg.getHost(), cfg.getPort());
        transport.connect(cfg.getHost(), cfg.getPort(), cfg.getLogin(), cfg.getPassword());
        try {
            transport.sendMessage(msg, InternetAddress.parse(recipient));
            log.info("Invite to {} was sent", recipient);
        } finally {
            transport.close();
        }
    } catch (UnsupportedEncodingException | MessagingException e) {
        throw new RuntimeException("Unable to send e-mail invite to " + recipient, e);
    }
}
 
开发者ID:kamax-io,项目名称:mxisd,代码行数:38,代码来源:EmailSmtpConnector.java

示例6: createMimeMessage

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
 *
 * @param session 和服务器交互的会话
 * @param mail 邮件内容
 * @return
 * @throws Exception
 */
private static MimeMessage createMimeMessage(Session session, String SendAccount, Mail mail) throws Exception {
    MimeMessage message = new MimeMessage(session);
    //From: 发件人
    message.setFrom(new InternetAddress(SendAccount, mail.getPersonal(), "UTF-8"));
    // To: 收件人
    message.setRecipients(MimeMessage.RecipientType.TO, mail.getAddresses());
    // Subject: 邮件主题
    message.setSubject(mail.getSubject(), "UTF-8");
    // Content: 邮件正文(可以使用html标签)
    message.setContent(mail.getContext(), "text/html;charset=UTF-8");
    // 设置发件时间
    message.setSentDate(new Date());
    message.saveChanges();
    return message;
}
 
开发者ID:BetaSummer,项目名称:sztw,代码行数:23,代码来源:MailCore.java

示例7: send

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
 * 发送邮件
 * @param receiver 接收者邮箱地址
 * @param subject 邮件主题
 * @param content 邮件内容
 */
public static void send(String receiver, String subject, String content) {
    try {
        //设置SSL连接、邮件环境
        Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
        final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
        Properties props = System.getProperties();
        props.setProperty("mail.smtp.host", SMTP_HOST);
        props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
        props.setProperty("mail.smtp.socketFactory.fallback", "false");
        props.setProperty("mail.smtp.port", SMTP_PORT);
        props.setProperty("mail.smtp.socketFactory.port", SMTP_SOCKET_FACTORY_PORT);
        props.setProperty("mail.smtp.auth", "true");
        //建立邮件会话
        Session session = Session.getDefaultInstance(props, new Authenticator() {
            //身份认证
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(SENDER, PASSWORD);
            }
        });
        //建立邮件对象
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(SENDER, SENDER_NAME));
        message.setRecipients(Message.RecipientType.TO, receiver);
        message.setSubject(subject);

        MimeBodyPart mimeBodyPart = new MimeBodyPart();
        mimeBodyPart.setContent(content, "text/html;charset=UTF-8");
        MimeMultipart mimeMultipart = new MimeMultipart();
        mimeMultipart.addBodyPart(mimeBodyPart);

        message.setContent(mimeMultipart);
        message.saveChanges();

        Transport.send(message);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:jthinking,项目名称:linux-memory-monitor,代码行数:45,代码来源:JavaMail.java

示例8: send

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public void send(String to, String cc, String bcc, String subject,
        String content, JavamailConfig javamailConfig)
        throws MessagingException {
    logger.debug("send : {}, {}", to, subject);

    try {
        Properties props = createSmtpProperties(javamailConfig);
        String username = javamailConfig.getUsername();
        String password = javamailConfig.getPassword();

        // 创建Session实例对象
        Session session = Session.getInstance(props, new SmtpAuthenticator(
                username, password));
        session.setDebug(false);

        // 创建MimeMessage实例对象
        MimeMessage message = new MimeMessage(session);
        // 设置邮件主题
        message.setSubject(subject);
        // 设置发送人
        message.setFrom(new InternetAddress(username));
        // 设置发送时间
        message.setSentDate(new Date());
        // 设置收件人
        message.setRecipients(RecipientType.TO, InternetAddress.parse(to));
        // 设置html内容为邮件正文,指定MIME类型为text/html类型,并指定字符编码为gbk
        message.setContent(content, "text/html;charset=gbk");

        // 保存并生成最终的邮件内容
        message.saveChanges();

        // 发送邮件
        Transport.send(message);
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:38,代码来源:JavamailService.java

示例9: send

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public boolean send() throws Exception {
    Properties props = _setProperties();
    Session session = Session.getInstance(props, this);
    MimeMessage msg = new MimeMessage(session);
    msg.setSubject(subject);
    msg.setFrom(new InternetAddress("[email protected]"));
    msg.setRecipients(MimeMessage.RecipientType.TO, new InternetAddress[] {
            new InternetAddress("[email protected]")
    });
    msg.setSentDate(new Date());
    msg.setContent(multipart);
    Transport.send(msg);
    return true;
}
 
开发者ID:KursX,项目名称:Parallator,代码行数:15,代码来源:MailSender.java

示例10: createAttachMail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
  * @Method: createAttachMail
  * @Description: ����һ����������ʼ�
  * @param session
  * @return
  * @throws Exception
  */ 
  public static MimeMessage createAttachMail(String subject, String content, String filePath) throws Exception{
      MimeMessage message = new MimeMessage(session);
      
      message.setFrom(new InternetAddress(username));
      if(recipients.contains(";")){
	List<InternetAddress> list = new ArrayList<InternetAddress>();
	String []median=recipients.split(";");
	for(int i=0;i<median.length;i++){
		list.add(new InternetAddress(median[i]));
	}
	InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
	message.setRecipients(Message.RecipientType.TO,address);
}else{
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
      message.setSubject(subject);
      MimeBodyPart text = new MimeBodyPart();
      text.setContent(content, "text/html;charset=UTF-8");
      
      MimeBodyPart attach = new MimeBodyPart();
      DataHandler dh = new DataHandler(new FileDataSource(filePath));
      attach.setDataHandler(dh);
      attach.setFileName(dh.getName());

      MimeMultipart mp = new MimeMultipart();
      mp.addBodyPart(text);
      mp.addBodyPart(attach);
      mp.setSubType("mixed");
      
      message.setContent(mp);
      message.saveChanges();
      return message;
  }
 
开发者ID:AlanYangs,项目名称:Log4Reports,代码行数:41,代码来源:EmailUtil.java

示例11: createImageMail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
  * @Method: createImageMail
  * @Description: ����һ���ʼ����Ĵ�ͼƬ���ʼ�
  * @param session
  * @return
  * @throws Exception
  */ 
  public static MimeMessage createImageMail(String subject, String content, String imagePath) throws Exception {

      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(username));
      if(recipients.contains(";")){
	List<InternetAddress> list = new ArrayList<InternetAddress>();
	String []median=recipients.split(";");
	for(int i=0;i<median.length;i++){
		list.add(new InternetAddress(median[i]));
	}
	InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
	message.setRecipients(Message.RecipientType.TO,address);
}else{
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
      message.setSubject(subject);
      MimeBodyPart text = new MimeBodyPart();
      text.setContent(content, "text/html;charset=UTF-8");
      MimeBodyPart image = new MimeBodyPart();
      DataHandler dh = new DataHandler(new FileDataSource(imagePath));
      image.setDataHandler(dh);
      image.setContentID("xxx.jpg");
      MimeMultipart mm = new MimeMultipart();
      mm.addBodyPart(text);
      mm.addBodyPart(image);
      mm.setSubType("related");

      message.setContent(mm);
      message.saveChanges();
      return message;
  }
 
开发者ID:AlanYangs,项目名称:Log4Reports,代码行数:39,代码来源:EmailUtil.java

示例12: createMixedMail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
  * @Method: createMixedMail
  * @Description: ����һ��������ʹ�ͼƬ���ʼ�
  * @param session
  * @return
  * @throws Exception
  */ 
  public static MimeMessage createMixedMail(String subject, String content, String imagePath, String filePath) throws Exception {
      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(username));
      if(recipients.contains(";")){
	List<InternetAddress> list = new ArrayList<InternetAddress>();
	String []median=recipients.split(";");
	for(int i=0;i<median.length;i++){
		list.add(new InternetAddress(median[i]));
	}
	InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
	message.setRecipients(Message.RecipientType.TO,address);
}else{
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
      message.setSubject(subject);
      
      MimeBodyPart text = new MimeBodyPart();
      text.setContent(content,"text/html;charset=UTF-8");
      
      MimeBodyPart image = new MimeBodyPart();
      image.setDataHandler(new DataHandler(new FileDataSource(imagePath)));
      image.setContentID("aaa.jpg");
      
      MimeBodyPart attach = new MimeBodyPart();
      DataHandler dh = new DataHandler(new FileDataSource(filePath));
      attach.setDataHandler(dh);
      attach.setFileName(dh.getName());

      MimeMultipart mp = new MimeMultipart();
      mp.addBodyPart(text);
      mp.addBodyPart(image);
      mp.setSubType("related");
      
      MimeBodyPart bodyContent = new MimeBodyPart();
      bodyContent.setContent(mp);
      message.saveChanges();
      return message;
  }
 
开发者ID:AlanYangs,项目名称:Log4Reports,代码行数:46,代码来源:EmailUtil.java

示例13: sendEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public static void sendEmail(EmailSettingContent emailSetting, String acceptor, String subject, String body) {
    Properties props = buildProperty(emailSetting);

    Session session = Session.getInstance(props, new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            String username = null;
            String password = null;
            if (emailSetting.isAuthenticated()) {
                username = emailSetting.getUsername();
                password = emailSetting.getPassword();
            }
            return new PasswordAuthentication(username, password);
        }
    });
    try {

        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(emailSetting.getSender()));
        message.setRecipients(Message.RecipientType.TO,
            InternetAddress.parse(acceptor));

        message.setSubject(subject, "utf8");
        message.setContent(body, "text/html;charset=utf8");
        Transport.send(message);

    } catch (Throwable throwable) {
    }
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:30,代码来源:SmtpUtil.java

示例14: buildMailMessage

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
private MimeMessage buildMailMessage(Session session, NotificationEvent notifyEvent, String title,
        String mailTemplatePath) throws MessagingException {

    MimeMessage message = new MimeMessage(session);

    // 邮件标题
    message.setSubject(title);

    String html = IOHelper.readTxtFile(mailTemplatePath, "utf-8");
    html = buildMailBody(html, notifyEvent);
    // 正文
    message.setContent(html, "text/html;charset=utf-8");
    // 发件人
    message.setFrom(username);

    String addressStr = notifyEvent.getArg(cName);
    String[] toAddr = addressStr.split(",");
    Address[] receiver = new Address[toAddr.length];
    int i = 0;
    for (String addr : toAddr) {
        if (!StringHelper.isEmpty(addr)) {
            receiver[i] = new InternetAddress(addr);
            i++;
        }
    }
    // 收件人
    message.setRecipients(MimeMessage.RecipientType.TO, receiver);

    message.saveChanges();

    return message;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:33,代码来源:JavaMailAction.java

示例15: sendMail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public void sendMail(String account) throws Exception {
	message = new MimeMessage(session);
	message.setFrom(new InternetAddress("[email protected]"));
	message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(account, false));
	message.setSubject("DO NOT REPLY");
	message.setDataHandler(new DataHandler(new ByteArrayDataSource(getMailContent(), "text/html")));
	message.setSentDate(new Date());

	transport = session.getTransport();
	transport.connect("smtp-mail.outlook.com", "[email protected]", "BaoZJ960606");
	transport.sendMessage(message, message.getAllRecipients());
	transport.close();
}
 
开发者ID:CongBao,项目名称:baozijuan.com,代码行数:14,代码来源:MailManager.java


注:本文中的javax.mail.internet.MimeMessage.setRecipients方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。