當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。