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


Java Message.setRecipient方法代码示例

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


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

示例1: sendTextMail

import javax.mail.Message; //导入方法依赖的package包/类
public boolean sendTextMail(MailSenderInfo mailInfo) {
    MyAuthenticator authenticator = null;
    Properties pro = mailInfo.getProperties();
    if (mailInfo.isValidate()) {
        authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
    }
    try {
        Message mailMessage = new MimeMessage(Session.getInstance(pro, authenticator));
        mailMessage.setFrom(new InternetAddress(mailInfo.getFromAddress()));
        mailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(mailInfo.getToAddress()));
        mailMessage.setSubject(mailInfo.getSubject());
        mailMessage.setSentDate(new Date());
        mailMessage.setText(mailInfo.getContent());
        Transport.send(mailMessage);
        return true;
    } catch (MessagingException ex) {
        ex.printStackTrace();
        return false;
    }
}
 
开发者ID:JamesLiAndroid,项目名称:AndroidKillerService,代码行数:21,代码来源:SimpleMailSender.java

示例2: sendMsg

import javax.mail.Message; //导入方法依赖的package包/类
public boolean sendMsg(String recipient, String subject, String content)
		throws MessagingException {
	// Create a mail object
	Session session = Session.getInstance(props, new Authenticator() {
		// Set the account information session,transport will send mail
		@Override
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(Constants.MAIL_USERNAME, Constants.MAIL_PASSWORD);
		}
	});
	session.setDebug(true);
	Message msg = new MimeMessage(session);
	try {
		msg.setSubject(subject);			//Set the mail subject
		msg.setContent(content,"text/html;charset=utf-8");
		msg.setFrom(new InternetAddress(Constants.MAIL_USERNAME));			//Set the sender
		msg.setRecipient(RecipientType.TO, new InternetAddress(recipient));	//Set the recipient
		Transport.send(msg);
		return true;
	} catch (Exception ex) {
		ex.printStackTrace();
		System.out.println(ex.getMessage());
		return false;
	}

}
 
开发者ID:ICT-BDA,项目名称:EasyML,代码行数:27,代码来源:JavaMail.java

示例3: sendAttachMail

import javax.mail.Message; //导入方法依赖的package包/类
public boolean sendAttachMail(MailSenderInfo mailInfo) {
    MyAuthenticator authenticator = null;
    Properties pro = mailInfo.getProperties();
    if (mailInfo.isValidate()) {
        authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
    }
    try {
        Message mailMessage = new MimeMessage(Session.getInstance(pro, authenticator));
        mailMessage.setFrom(new InternetAddress(mailInfo.getFromAddress()));
        mailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(mailInfo.getToAddress()));
        mailMessage.setSubject(mailInfo.getSubject());
        mailMessage.setSentDate(new Date());
        Multipart multi = new MimeMultipart();
        BodyPart textBodyPart = new MimeBodyPart();
        textBodyPart.setContent(mailInfo.getContent(), "text/html; charset=utf-8");
        multi.addBodyPart(textBodyPart);
        for (String path : mailInfo.getAttachFileNames()) {
            DataSource fds = new FileDataSource(path);
            BodyPart fileBodyPart = new MimeBodyPart();
            fileBodyPart.setDataHandler(new DataHandler(fds));
            fileBodyPart.setFileName(path.substring(path.lastIndexOf("/") + 1));
            multi.addBodyPart(fileBodyPart);
        }
        mailMessage.setContent(multi);
        mailMessage.saveChanges();
        Transport.send(mailMessage);
        return true;
    } catch (MessagingException ex) {
        ex.printStackTrace();
        return false;
    }
}
 
开发者ID:JamesLiAndroid,项目名称:AndroidKillerService,代码行数:33,代码来源:SimpleMailSender.java

示例4: sendMessage

import javax.mail.Message; //导入方法依赖的package包/类
private void sendMessage()
  {
      try {
          String smtpHost="smtp.gmail.com";
          String smtpUsername ="[email protected]";
          String smtpPassword ="OurAccountEnterprise2015";
          String from ="[email protected]";
          String to="[email protected]";
          String info = "Mensagem enviada de NICON SEGUROS SA por "+feedBack.getNome()+"\n\n"+feedBack.getMensagem()+"\n\n"+feedBack.getEmailResposta();
    
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
              props.put("mail.debug", "true");

Session session = Session.getInstance(props,
  new javax.mail.Authenticator() {
                      @Override
	protected PasswordAuthentication getPasswordAuthentication() {
		return new PasswordAuthentication(smtpUsername, smtpPassword);
	}
  });

          Message message = new MimeMessage(session);
          message.setFrom(new InternetAddress(from));
          message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
          message.setSubject(feedBack.getAssunto());
          message.setText(info);
          Transport.send(message);
      
          Mensagem.addInfoMsg("Mensagem enviada com sucesso");
          Validacao.atualizar("formEmail", "growlFeedBack");
          RequestContext.getCurrentInstance().execute("messageSent()");
      } 
      catch (MessagingException ex)
      {  
          Mensagem.addErrorMsg("Erro a enviar mensagem\n"+ex.getMessage());
          Validacao.atualizar("formEmail", "growlFeedBack");
      }  
  }
 
开发者ID:JIGAsoftSTP,项目名称:NICON,代码行数:43,代码来源:FeedBackBean.java


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