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


Java Message.setSubject方法代码示例

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


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

示例1: sendMail

import javax.mail.Message; //导入方法依赖的package包/类
public static void sendMail(String host, int port, String username, String password, String recipients,
		String subject, String content, String from) throws AddressException, MessagingException {
	
	Properties props = new Properties();
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.starttls.enable", "true");
	props.put("mail.smtp.host", host);
	props.put("mail.smtp.port", port);

	Session session = Session.getInstance(props, new javax.mail.Authenticator() {
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(username, password);
		}
	});

	Message message = new MimeMessage(session);
	message.setFrom(new InternetAddress(from));
	message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
	message.setSubject(subject);
	message.setText(content);

	Transport.send(message);
}
 
开发者ID:bndynet,项目名称:web-framework-for-java,代码行数:24,代码来源:MailHelper.java

示例2: sendCode

import javax.mail.Message; //导入方法依赖的package包/类
public static String sendCode(User user, HttpServletRequest request) {
    try {
        Session session = EmailActions.authorizeWebShopEmail();

        String code = Long.toHexString(Double.doubleToLongBits(Math.random()));
        request.getSession().setAttribute("deleteAccountCode", code);
        request.getSession().setAttribute("userName", user.getLogin());
        System.out.println(code);

        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(ApplicationProperties.SHOP_EMAIL));
        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(user.geteMail(), false));
        msg.setSubject("Delete account");
        msg.setText("Link : " + ApplicationProperties.URL + ApplicationProperties.PROJECT_NAME + "account/deleteAccountCode/" + code);
        msg.setSentDate(new Date());
        Transport.send(msg);

    } catch (MessagingException e) {
        System.out.println("Error : " + e);
    }
    return "loginAndRegistration/reset/codePassword";
}
 
开发者ID:xSzymo,项目名称:Spring-web-shop-project,代码行数:23,代码来源:SendEmailDeleteAccount.java

示例3: createMessage

import javax.mail.Message; //导入方法依赖的package包/类
private static Message createMessage(Session session)
        throws MessagingException, IOException {
    Message msg = new MimeMessage(session);
    InternetAddress fromAddress = new InternetAddress(
            getVal("from.mail"), getVal("username"));
    msg.setFrom(fromAddress);
    Optional.ofNullable(getVal("to.mail")).ifPresent((String tos) -> {
        for (String to : tos.split(";")) {
            try {
                msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
                        to, to));
            } catch (Exception ex) {
                Logger.getLogger(Mailer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });

    msg.setSubject(parseSubject(getVal("msg.subject")));
    msg.setContent(getMessagePart());
    return msg;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:22,代码来源:Mailer.java

示例4: sendEmailWithOrder

import javax.mail.Message; //导入方法依赖的package包/类
public static void sendEmailWithOrder(String text, String eMail, HttpServletRequest request) {
    try {
        Session session = EmailActions.authorizeWebShopEmail();

        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(ApplicationProperties.SHOP_EMAIL));
        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(eMail, false));
        msg.setSubject("Shop order");
        msg.setText(text);
        msg.setSentDate(new Date());
        Transport.send(msg);
    } catch (MessagingException e) {
        System.out.println("Error : " + e);
    }
}
 
开发者ID:xSzymo,项目名称:Spring-web-shop-project,代码行数:16,代码来源:SendEmailUserAccount.java

示例5: sendTextEmail

import javax.mail.Message; //导入方法依赖的package包/类
public static void sendTextEmail(String recvEmail) {
	try { 
		Properties props = new Properties();
		props.setProperty("mail.transport.protocol", "smtp");
		props.setProperty("mail.host", "smtp.qq.com");
		props.setProperty("mail.smtp.auth", "true");
		props.put("mail.smtp.ssl.enable", "true");
		props.put("mail.smtp.socketFactory.port",  "994");
		Session session = Session.getInstance(props, new Authenticator() {
			@Override
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication("463112653", "manllfvunnfwbjhh");
			}
		});
		session.setDebug(true);
		Message msg = new MimeMessage(session);
		msg.setSubject("Hello Vme");
		//整个邮件的MultiPart(不能直接加入内容,需要在bodyPart中加入)
		Multipart emailPart = new MimeMultipart();
		MimeBodyPart attr1 = new MimeBodyPart();
		attr1.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/2601169057.png")));
		attr1.setFileName("tip.pic");
		
		MimeBodyPart attr2 = new MimeBodyPart();
		attr2.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/1724836491.png")));
		attr2.setFileName(MimeUtility.encodeText("哦图像"));
		
		MimeBodyPart content = new MimeBodyPart();
		MimeMultipart contentPart = new MimeMultipart();
		
		MimeBodyPart imgPart = new MimeBodyPart();
		imgPart.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/1724836491.png")));
		imgPart.setContentID("pic");
		
		MimeBodyPart htmlPart = new MimeBodyPart();
		htmlPart.setContent("<h1><a href='www.baidu.com'>百度一下</a><img src='cid:pic'/></h1>", "text/html;charset=utf-8");
		
		contentPart.addBodyPart(imgPart);
		contentPart.addBodyPart(htmlPart);
		content.setContent(contentPart);
		
		emailPart.addBodyPart(attr1);
		emailPart.addBodyPart(attr2);
		emailPart.addBodyPart(content);
		msg.setContent(emailPart);
		
		msg.setFrom(new InternetAddress("[email protected]"));
		msg.setRecipients(RecipientType.TO, InternetAddress.parse("[email protected],[email protected]"));
		msg.setRecipients(RecipientType.CC, InternetAddress.parse("[email protected],[email protected]"));
		Transport.send(msg);
	} catch (Exception e) {
		e.printStackTrace();
	} 
}
 
开发者ID:Fetax,项目名称:Fetax-AI,代码行数:55,代码来源:EmailHelper.java

示例6: sendHtmlMail

import javax.mail.Message; //导入方法依赖的package包/类
public boolean sendHtmlMail(MailSenderInfo mailInfo) {
    XLog.d("发送网页版邮件!");
    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()));
        String[] receivers = mailInfo.getReceivers();
        Address[] tos = new InternetAddress[receivers.length];
        for (int i = 0; i < receivers.length; i++) {
            tos[i] = new InternetAddress(receivers[i]);
        }
        mailMessage.setRecipients(Message.RecipientType.TO, tos);
        mailMessage.setSubject(mailInfo.getSubject());
        mailMessage.setSentDate(new Date());

        Multipart mainPart = new MimeMultipart();
        BodyPart html = new MimeBodyPart();
        html.setContent(mailInfo.getContent(), "text/html; charset=utf-8");
        mainPart.addBodyPart(html);
        mailMessage.setContent(mainPart);
        Transport.send(mailMessage);
        return true;
    } catch (MessagingException ex) {
        ex.printStackTrace();
        return false;
    }
}
 
开发者ID:JamesLiAndroid,项目名称:AndroidKillerService,代码行数:32,代码来源:SimpleMailSender.java

示例7: sendMail

import javax.mail.Message; //导入方法依赖的package包/类
/**
 * 发邮件处理
 * 
 * @param toAddr
 *            邮件地址
 * @param content
 *            邮件内容
 * @return 成功标识
 */
public static boolean sendMail(String toAddr, String title, String content, boolean isHtmlFormat) {

    final String username = YiDuConstants.yiduConf.getString(YiDuConfig.MAIL_SMTP_USERNAME);
    final String password = YiDuConstants.yiduConf.getString(YiDuConfig.MAIL_SMTP_PASSWORD);

    Properties props = new Properties();
    props.put("mail.smtp.auth", YiDuConstants.yiduConf.getBoolean(YiDuConfig.MAIL_SMTP_AUTH, true));
    props.put("mail.smtp.starttls.enable",
            YiDuConstants.yiduConf.getBoolean(YiDuConfig.MAIL_SMTP_STARTTLS_ENABLE, true));
    props.put("mail.smtp.host", YiDuConstants.yiduConf.getString(YiDuConfig.MAIL_SMTP_HOST));
    props.put("mail.smtp.port", YiDuConstants.yiduConf.getInt(YiDuConfig.MAIL_SMTP_PORT, 25));

    Session session = Session.getInstance(props, new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    });

    try {
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(YiDuConstants.yiduConf.getString(YiDuConfig.MAIL_SMTP_FROM)));
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toAddr));
        message.setSubject(title);
        if (isHtmlFormat) {
            message.setContent(content, "text/html");
        } else {
            message.setText(content);
        }
        Transport.send(message);

    } catch (MessagingException e) {
        logger.warn(e);
        return false;
    }
    return true;

}
 
开发者ID:luckyyeah,项目名称:YiDu-Novel,代码行数:47,代码来源:MailUtils.java

示例8: send

import javax.mail.Message; //导入方法依赖的package包/类
boolean send(String title, String body, String toAddr) {
    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", HOST);
    props.put("mail.smtp.port", PORT);

    Session session = Session.getInstance(props,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(USER_NAME, PASSWORD);
                }
            });
    try {
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(USER_NAME));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse(toAddr));
        message.setSubject(title);
        message.setText(body);

        Transport.send(message);

        System.out.println("Mail sent.");
        return true;

    } catch (MessagingException e) {
        e.printStackTrace();
    }
    return false;
}
 
开发者ID:mrqyoung,项目名称:SMS302,代码行数:32,代码来源:MailSender.java

示例9: sendMail

import javax.mail.Message; //导入方法依赖的package包/类
public void sendMail(String uEmail, String URLlink, String Uname, String mailuser, String mailpass, String mailserver, String mailport, String mailsendadd) {
	
	Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", mailserver);
    props.put("mail.smtp.port", mailport);

    Session session = Session.getInstance(props,
      new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(mailuser, mailpass);
        }
      });

    try {

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(mailsendadd));
        message.setRecipients(Message.RecipientType.TO,
            InternetAddress.parse(uEmail));
        message.setSubject("Activate your account!!!");
        message.setContent("Dear "+Uname+", <BR><BR> Please click the following link to activate your account. <BR><BR> <a href=\""+URLlink+"\">Activate Account</a> <BR><BR> Thank You,", "text/html; charset=utf-8");
       
        Transport.send(message);

        System.out.println("Create Account E-mail Sent");

    } catch (MessagingException e) {
        
        System.out.println("Error - Create Account E-mail Send FAILED");
        throw new RuntimeException(e);
    }
}
 
开发者ID:CanadianRepublican,项目名称:DDNS_Server,代码行数:35,代码来源:CreateServlet.java

示例10: sendSMS

import javax.mail.Message; //导入方法依赖的package包/类
public void sendSMS(String smsMessage_arg)
{
	props = new Properties(); 
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.starttls.enable", "true");
	props.put("mail.smtp.host", "outlook.office365.com");
	props.put("mail.smtp.port", "587");
	session = Session.getInstance(props, new javax.mail.Authenticator() 
	{
			protected PasswordAuthentication getPasswordAuthentication() 
			{
				return new PasswordAuthentication(getUsername(), getPassword());
			}
	});
	System.out.println("Authentication Complete");
	try
	{
		setSms(smsMessage_arg);
		Message msg = new MimeMessage(session);
		msg.setFrom(new InternetAddress("[email protected]", "memoranda"));
		msg.addRecipient(Message.RecipientType.TO, new InternetAddress(getAddress(), "smsLine"));
		msg.setSubject("Memoranda ");
		msg.setText(getSms());
		Transport.send(msg);
	}
	catch(Exception emailErr )
	{ 
		System.out.println("error sending email...\n");
		emailErr.printStackTrace(System.out);
	}	
}
 
开发者ID:ser316asu,项目名称:Wilmersdorf_SER316,代码行数:32,代码来源:SMS.java

示例11: sendTextEmail

import javax.mail.Message; //导入方法依赖的package包/类
/**
 * 
 * @param recvEmail 收件人可多个,用","隔开
 * @param title  标题
 * @param text   邮件内容
 */
public static void sendTextEmail(String recvEmail, String title, String text) {
	try { 
		Properties props = new Properties();
		props.setProperty("mail.transport.protocol", "smtp");
		props.setProperty("mail.host", "smtp.qq.com");
		props.setProperty("mail.smtp.auth", "true");
		props.put("mail.smtp.ssl.enable", "true");
		props.put("mail.smtp.socketFactory.port",  "994");
		Session session = Session.getInstance(props, new Authenticator() {
			@Override
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication("463112653", "manllfvunnfwbjhh");
			}
		});
		session.setDebug(true);
		Message msg = new MimeMessage(session);
		msg.setSubject(title);
		msg.setText(text);
		msg.setFrom(new InternetAddress("[email protected]"));
		msg.setRecipients(RecipientType.TO, InternetAddress.parse(recvEmail));
		msg.setRecipients(RecipientType.CC, InternetAddress.parse(recvEmail));
		Transport.send(msg);
	} catch (Exception e) {
		e.printStackTrace();
	} 
}
 
开发者ID:Awesky,项目名称:awe-awesomesky,代码行数:33,代码来源:EmailHelper.java

示例12: sendUsername

import javax.mail.Message; //导入方法依赖的package包/类
@RequestMapping(value = "sendUsername", method = RequestMethod.POST)
public String sendUsername(@RequestParam("email") String email, Model model, HttpServletResponse response,
                           HttpServletRequest request) {

    if ((usersService.findByEmail(email) == null)) {
        model.addAttribute("msg", "Wrong e-mail");
        return "loginAndRegistration/reset/forgotUsername";
    }
    User user = usersService.findByEmail(email);

    try {
        Session session = EmailActions.authorizeWebShopEmail();

        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(ApplicationProperties.SHOP_EMAIL));
        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email, false));
        msg.setSubject("Your login");
        msg.setText("Login : " + user.getLogin());
        msg.setSentDate(new Date());
        Transport.send(msg);
    } catch (MessagingException e) {
        System.out.println("Error : " + e);
    }

    model.addAttribute("msg", "Success");

    return "loginAndRegistration/reset/forgotUsername";
}
 
开发者ID:xSzymo,项目名称:Spring-web-shop-project,代码行数:29,代码来源:SendEmailForgetPasswordLogin.java

示例13: start

import javax.mail.Message; //导入方法依赖的package包/类
/**
 * Sent an email using SMTP protocol
 * @return mailSent boolean true if mail has been sent successfully
 */
public boolean start()
{
	
	System.out.println("*********************************  Recipient "+this.recipient);
	
	Properties props = new Properties();
	
	//Using TLS
//	props.put("mail.smtp.auth", "true");
//	props.put("mail.smtp.starttls.enable", "true");
//	props.put("mail.smtp.host", smtpServer);
//	props.put("mail.smtp.port", "587"); 
	
	// using SSL
	props.put("mail.smtp.host", this.smtpServer);
	props.put("mail.smtp.socketFactory.port", "465");
	props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.port", "465");

  
  Session session = Session.getDefaultInstance(props,new javax.mail.Authenticator()
  {
              @Override
              protected PasswordAuthentication getPasswordAuthentication()
              {
                  return new PasswordAuthentication(username, password);
              }
  }
  );
  
  try 
  {
      Message message = new MimeMessage(session);
      message.setFrom(new InternetAddress(username));
      message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(this.recipient));
      message.setSubject(this.subject);
      message.setText(this.emailBody);
      Transport.send(message);	
      
      System.out.println("Mail.sendMail() Mail sent");
      mailSent = true ;	  
  } 
  catch (Exception e) 
  {
	  System.out.println("Mail.sendMail() Unable to sent mail ");
	  e.printStackTrace();
	  mailSent = false ;
  } 
  
  return(mailSent);		
}
 
开发者ID:Will30,项目名称:MonitorYourLAN,代码行数:57,代码来源:Mail.java

示例14: sendTextMail

import javax.mail.Message; //导入方法依赖的package包/类
/**
 * 以文本格式发送邮件
 * 
 * @param mailInfo
 *            待发送的邮件的信息
 */
public boolean sendTextMail(MailSenderObj mailInfo) {
	// 判断是否需要身份认证
	MyAuthenticator authenticator = null;
	Properties pro = mailInfo.getProperties();
	if (mailInfo.isValidate()) {
		// 如果需要身份认证,则创建一个密码验证器
		authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
	}
	// 根据邮件会话属性和密码验证器构造一个发送邮件的session
	Session sendMailSession = Session.getDefaultInstance(pro, authenticator);
	try {
		// 根据session创建一个邮件消息
		Message mailMessage = new MimeMessage(sendMailSession);
		// 创建邮件发送者地址
		Address from = new InternetAddress(mailInfo.getFromAddress());
		// 设置邮件消息的发送者
		mailMessage.setFrom(from);
		// 创建邮件的接收者地址,并设置到邮件消息中
		String[] asToAddr = mailInfo.getToAddress();
		if (asToAddr == null) {
			logger.debug("邮件发送失败,收信列表为空" + mailInfo);
			return false;
		}
		for (int i=0; i<asToAddr.length; i++) {
			if (asToAddr[i] == null || asToAddr[i].equals("")) {
				continue;
			}
			Address to = new InternetAddress(asToAddr[i]);
			mailMessage.addRecipient(Message.RecipientType.TO, to);
		}
		// 设置邮件消息的主题
		mailMessage.setSubject(mailInfo.getSubject());
		// 设置邮件消息发送的时间
		mailMessage.setSentDate(new Date());
		// 设置邮件消息的主要内容
		String mailContent = mailInfo.getContent();
		mailMessage.setText(mailContent);
		// 发送邮件
		Transport.send(mailMessage);
		logger.info("发送邮件成功。" + mailInfo);
		return true;
	} catch (MessagingException ex) {
		logger.error("发送邮件失败:" + ex.getMessage() + Arrays.toString(ex.getStackTrace()));
		ex.printStackTrace();
	}
	return false;
}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:54,代码来源:SimpleMailSender.java

示例15: send

import javax.mail.Message; //导入方法依赖的package包/类
public static void send(String tomail,String msg){  
	// Recipient's email ID needs to be mentioned.
     //String to = "[email protected]";
  String to = tomail;

     // Sender's email ID needs to be mentioned
     String from = "[email protected]";//change accordingly
     final String username = "[email protected]";//change accordingly
     final String password = "rohanaudia8";//change accordingly

     // Assuming you are sending email through relay.jangosmtp.net
     String host = "smtp.gmail.com";

     Properties props = new Properties();
     props.put("mail.smtp.auth", "true");
     props.put("mail.smtp.starttls.enable", "true");
     props.put("mail.smtp.host", host);
     props.put("mail.smtp.port", "587");

     // Get the Session object.
     Session session = Session.getInstance(props,
     new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
           return new PasswordAuthentication(username, password);
        }
     });

     try {
        // Create a default MimeMessage object.
        Message message = new MimeMessage(session);

        // Set From: header field of the header.
        message.setFrom(new InternetAddress(from));

        // Set To: header field of the header.
        message.setRecipients(Message.RecipientType.TO,
        InternetAddress.parse(to));

        // Set Subject: header field
        message.setSubject("Login Credentials");

        // Now set the actual message
        message.setText("" + msg);

        // Send message
        Transport.send(message);

        System.out.println("Sent message successfully....");

     } catch (MessagingException e) {
           throw new RuntimeException(e);
     }
}
 
开发者ID:rohanpillai20,项目名称:Web-Based-Graphical-Password-Authentication-System,代码行数:54,代码来源:FP.java


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