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


Java MimeMessage.setRecipient方法代码示例

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


在下文中一共展示了MimeMessage.setRecipient方法的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: createCodeMessage

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
 * 创建一封邮件
 *
 * @param session     和服务器交互的会话
 * @param sendMail    发件人邮箱
 * @param receiveMail 收件人邮箱
 * @return
 * @throws Exception
 */
private MimeMessage createCodeMessage(Session session, String sendMail, String receiveMail) throws MessagingException, UnsupportedEncodingException {
    MimeMessage message = new MimeMessage(session);

    message.setFrom(new InternetAddress(sendMail, "吃在华科", "UTF-8"));

    message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, this.name, "UTF-8"));

    message.setSubject("吃在华科邮件注册验证码", "UTF-8");
    String content = this.name + ",你好, 您的验证码如下<br/>" + getCode() + "<p> 您不需要回复这封邮件。<p/>";
    message.setContent(content, "text/html;charset=UTF-8");
    message.setSentDate(new Date());
    message.saveChanges();

    return message;
}
 
开发者ID:GrayXu,项目名称:HustEating,代码行数:25,代码来源:Mail.java

示例3: buildEmailMessage

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
private Message buildEmailMessage(EmailInfo emailInfo)
		throws AddressException, MessagingException, UnsupportedEncodingException {
	MimeMessage message = new MimeMessage(this.session);
	message.setFrom(new InternetAddress(emailInfo.getFrom(), "网页更新订阅系统", "UTF-8"));
	message.setRecipient(Message.RecipientType.TO, new InternetAddress(emailInfo.getTo()));

	Multipart multipart = new MimeMultipart();
	BodyPart messageBodyPart = new MimeBodyPart();
	messageBodyPart.setContent(emailInfo.getContent(), "text/html;charset=UTF-8");
	multipart.addBodyPart(messageBodyPart);
	message.setContent(multipart);
	message.setSubject(emailInfo.getTitle());
	message.saveChanges();
	return message;
}
 
开发者ID:wrayzheng,项目名称:webpage-update-subscribe,代码行数:16,代码来源:EmailServer.java

示例4: createMimeMessage

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
 * 创建一封只包含文本的简单邮件
 *
 * @param session
 *            和服务器交互的会话
 * @param sendMail
 *            发件人邮箱
 * @param receiveMail
 *            收件人邮箱
 * @return
 * @throws Exception
 */
public static MimeMessage createMimeMessage(Session session, String sendMail, String receiveMail, String username,String pwd)
		throws Exception {
	// 1. 创建一封邮件
	MimeMessage message = new MimeMessage(session);

	// 2. From: 发件人(昵称有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改昵称)
	message.setFrom(new InternetAddress(sendMail, "Mircle", "UTF-8"));

	// 3. To: 收件人(可以增加多个收件人、抄送、密送)
	message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "", "UTF-8"));

	// 4. Subject: 邮件主题(标题有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改标题)
	message.setSubject(subject, "UTF-8");

	// 5. Content: 邮件正文(可以使用html标签)(内容有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改发送内容)
	message.setContent(getContent(username,pwd), "text/html;charset=UTF-8");

	// 6. 设置发件时间
	message.setSentDate(new Date());

	// 7. 保存设置
	message.saveChanges();

	return message;
}
 
开发者ID:miracle857,项目名称:weibo,代码行数:38,代码来源:Mail.java

示例5: sendAccountActivateEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public static void sendAccountActivateEmail(String email, String uuid, int userId) {
  Session session;
  try {
    session = getSession();
    MimeMessage message = new MimeMessage(session);
    message.setSubject("������֤��");
    message.setSentDate(new Date());
    message.setFrom(new InternetAddress(FROM));
    message.setRecipient(RecipientType.TO, new InternetAddress(email));
    message.setContent("�����û�"+userId+":������֤��Ϊ��"+uuid,
        "text/html;charset=utf-8");
    message.saveChanges();
    Transport.send(message);
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:Luodian,项目名称:Higher-Cloud-Computing-Project,代码行数:18,代码来源:EmailUtils.java

示例6: createFeedBackMsg

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
 * 创建一封反馈邮件
 * @param session
 * @param sendMail
 * @param detail
 * @return
 */
private MimeMessage createFeedBackMsg(Session session, String sendMail, String detail) throws UnsupportedEncodingException, MessagingException {
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(sendMail, "吃在华科", "UTF-8"));
    message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress("[email protected]", this.name, "UTF-8"));
    message.setSubject("吃在华科用户反馈", "UTF-8");
    String content = UserStatus.getUserStatus().getName()+"\n"+detail;
    message.setContent(content, "text/html;charset=UTF-8");
    message.setSentDate(new Date());
    message.saveChanges();
    return message;
}
 
开发者ID:GrayXu,项目名称:HustEating,代码行数:19,代码来源:Mail.java

示例7: sendMail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
 * Sends email.
 * 
 * @throws MessagingException
 *             message exception
 */
private void sendMail() throws MessagingException {

	/*
	 * Properties used to construct a email sending connection protocal.
	 */
	final Properties props = new Properties();

	props.put("mail.smtp.host", MAIL_HOST);
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.starttls.enable", "true");

	final Authenticator auth = new SMTPAuthenticator();
	final MimeMessage msg = new MimeMessage(Session.getDefaultInstance(props, auth));

	msg.setFrom(new InternetAddress(from));
	msg.setRecipient(RecipientType.TO, new InternetAddress(to));
	msg.setSubject(subject);
	msg.setText(message);
	Transport.send(msg);
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:27,代码来源:EmailSender.java

示例8: report

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public void report(UserSetting userSetting, SearchResult searchResult, int resultState) {
    if(! (boolean)config.get("enableMailReport"))
        return;
    
    final Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.host", "smtp.163.com");
    props.put("mail.user", config.get("fromEmailUser"));
    props.put("mail.password", config.get("fromEmailPassword"));

    // 构建授权信息,用于进行SMTP进行身份验证
    Authenticator authenticator = new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(props.getProperty("mail.user"), props.getProperty("mail.password"));
        }
    };
    Session mailSession = Session.getInstance(props, authenticator);
    try {
    MimeMessage message = new MimeMessage(mailSession);
    message.setFrom(new InternetAddress(props.getProperty("mail.user")));
    message.setRecipient(RecipientType.TO, new InternetAddress(config.get("toEmailUser").toString()));
    message.setSubject("PTE助手通知");

    String content = String.format("账号 %s 已搜索到可用约会: 时间=%s, 地点=%s",
            userSetting.user.username, CalendarUtils.chinese(searchResult.apptTime), searchResult.testCenter);
    if(resultState > -1) {
        content += "<br>";
        content += resultState == 1 ? "并报名成功" : "但报名失败";
    }
    message.setContent(content, "text/html;charset=UTF-8");
    
    Transport.send(message);
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}
 
开发者ID:hulang1024,项目名称:PTEAssistant,代码行数:38,代码来源:EamilReporter.java

示例9: test

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public void test() throws Exception {

        Properties props = System.getProperties();
        props.put("mail.transport.protocol", "smtps");
        props.put("mail.smtp.port", PORT);

        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.starttls.required", "true");

        Session session = Session.getInstance(props);

        MimeMessage msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(FROM));
        msg.setRecipient(Message.RecipientType.TO, new InternetAddress(TO));
        msg.setSubject(SUBJECT);
        msg.setContent(BODY, "text/plain");

        Transport transport = session.getTransport();

        try {
            transport.connect(HOST, SMTP_USERNAME, SMTP_PASSWORD);
            transport.sendMessage(msg, msg.getAllRecipients());
        } finally {
            transport.close();
        }

    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:29,代码来源:NotificiationMailTest.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: createMimeMessage

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
private static MimeMessage createMimeMessage(MessageBean msgBean, String mimeSubtype, Session session) throws MessagingException {
    MimeMessage msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(msgBean.getFrom()));
    msg.setRecipient(Message.RecipientType.TO, new InternetAddress(msgBean.getTo()));
    msg.setSubject(msgBean.getSubject());
    msg.setText(msgBean.getContent(), Charset.defaultCharset().name(), mimeSubtype);
    return msg;
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:9,代码来源:EmailHelper.java

示例14: send

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public void send() throws Exception{
	if(this.mail.getContentType() == null){
		this.mail.setContentType(MailContentTypeEnum.HTML.getValue());
	}
	
	if(null == this.mail.getContent() || "".equals(this.mail.getContent())){
		throw new Exception("邮件内容没有设置");
	}
	
	if(null == this.mail.getTitle()|| "".equals(this.mail.getTitle())){
		throw new Exception("邮件标题没有设置");
	}
	
	if(null == this.mail.getSendAddress()|| this.mail.getSendAddress().isEmpty()){
		throw new Exception("邮件发送地址没有设置");
	}
	
	final PropertiesUtil util = new PropertiesUtil("mail");
	
	//设置邮件服务器登陆信息
	final Properties props = new Properties();
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.host", util.getValue("mail.smtp.service"));
	props.put("mail.smtp.port", util.getValue("mail.smtp.port"));
	props.put("mail.user", util.getValue("mail.from.address"));
	props.put("mail.password", util.getValue("mail.from.smtp.pwd"));
	
	// 构建授权信息,用于进行SMTP进行身份验证
	Authenticator authenticator = new Authenticator(){
           protected PasswordAuthentication getPasswordAuthentication() {
               // 用户名、密码
               String userName = props.getProperty("mail.user");
               String password = props.getProperty("mail.password");
               return new PasswordAuthentication(userName, password);
           }
	};
	
	// 使用环境属性和授权信息,创建邮件会话
	Session mailSession = Session.getInstance(props, authenticator);
	
     // 创建邮件消息
       MimeMessage message = new MimeMessage(mailSession);
       
       // 设置发件人昵称
       String nickName = MimeUtility.encodeText(util.getValue("mail.from.nickname"));
       InternetAddress form = new InternetAddress(nickName + " <" + props.getProperty("mail.user") + ">");
       message.setFrom(form);
       
       // 设置邮件标题
       message.setSubject(mail.getTitle());
       
       //html发送邮件
       if(mail.getContentType().equals(MailContentTypeEnum.HTML.getValue())) {
           // 设置邮件内容
           message.setContent(mail.getContent(), mail.getContentType());
       }
       //文本发送邮件
       else if(mail.getContentType().equals(MailContentTypeEnum.TEXT.getValue())){
       	// 设置邮件内容
           message.setText(mail.getContent());
       }
       
       //发送邮箱地址
       List<String> targets = mail.getSendAddress();
       
       for(int i = 0;i < targets.size();i++){
           try {
               // 设置收件人的邮箱
               InternetAddress to = new InternetAddress(targets.get(i));
               message.setRecipient(Message.RecipientType.TO, to);
               // 最后当然就是发送邮件啦
               Transport.send(message);
           }catch (Exception e)
           {
           	e.printStackTrace();
           }

       }
}
 
开发者ID:SnailFastGo,项目名称:springboot_op,代码行数:80,代码来源:MailSender.java

示例15: createMimeMessage

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
private static MimeMessage createMimeMessage(Session session, String sendMail, 
		String receiveMail, String password) throws Exception {

    MimeMessage message = new MimeMessage(session);


    message.setFrom(new InternetAddress(sendMail, "易购房", "UTF-8"));

 
    message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "亲爱的用户", "UTF-8"));

    // 4. Subject: 主题
    message.setSubject("找回密码", "UTF-8");

    // 5. Content: 内容
    message.setContent("您好,以下为您的密码,请及时修改~\n" + "密码:" + password, "text/html;charset=UTF-8");


    message.setSentDate(new Date());

    message.saveChanges();

    return message;
}
 
开发者ID:632team,项目名称:EasyHousing,代码行数:25,代码来源:Tool.java


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