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


Java Message.setText方法代码示例

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


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

示例3: 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

示例4: sendMail

import javax.mail.Message; //导入方法依赖的package包/类
private void sendMail(String subject, String body, MailSettings settings) throws MessagingException {

        Properties props = new Properties();
        props.put("mail.transport.protocol", "smtp");
        props.put("mail.smtp.host", settings.getSmtpServer());
        props.put("mail.smtp.port", settings.getSmtpPort() + "");

        if (settings.getMode() == MailSettings.Mode.SSL) {
            props.put("mail.smtp.socketFactory.port", settings.getSmtpPort() + "");
            props.put("mail.smtp.socketFactory.class",
                    "javax.net.ssl.SSLSocketFactory");
        } else if (settings.getMode() == MailSettings.Mode.TLS) {
            props.put("mail.smtp.starttls.enable", "true");
        }

        props.put("mail.smtp.auth", settings.isUseAuth() + "");

        Session session;
        if (settings.isUseAuth()) {
            session = Session.getInstance(props,
                    new javax.mail.Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(settings.getUser(), settings.getPass());
                }
            });
        } else {
            session = Session.getInstance(props);
        }

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(settings.getFrom()));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse(settings.getTo()));
        message.setSubject(subject);
        message.setText(body);

        Transport.send(message);

    }
 
开发者ID:dainesch,项目名称:HueSense,代码行数:41,代码来源:MailService.java

示例5: sendMail

import javax.mail.Message; //导入方法依赖的package包/类
public void sendMail(){
	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");

	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(from));
		message.setRecipients(Message.RecipientType.TO,
				InternetAddress.parse(to));
		message.setSubject("Website Status Notification.");
		message.setText("website is down .");

		Transport.send(message);

		System.out.println("Done");

	} catch (MessagingException e) {
		System.out.println("Error sending email.");
		e.printStackTrace();
	}
}
 
开发者ID:naeemkhan12,项目名称:websiteMonitor,代码行数:33,代码来源:mail.java

示例6: sendCode

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

    if ((usersService.findByEmail(email) == null)) {
        model.addAttribute("msg", "Wrong e-mail");
        return "loginAndRegistration/reset/forgotPassword";
    } else if (usersService.findByLogin(login) == null) {
        model.addAttribute("msg", "Wrong login");
        return "loginAndRegistration/reset/forgotPassword";
    }

    try {
        Session session = EmailActions.authorizeWebShopEmail();

        String code = Long.toHexString(Double.doubleToLongBits(Math.random()));
        request.getSession().setAttribute("code", code);
        request.getSession().setAttribute("email", email);

        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(ApplicationProperties.SHOP_EMAIL));
        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email, false));
        msg.setSubject("Reset password");
        msg.setText("After 5 min code will be delete\n" + 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,代码行数:33,代码来源:SendEmailForgetPasswordLogin.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: _setupMessage

import javax.mail.Message; //导入方法依赖的package包/类
/**
 * Set up a new message.
 */
private Message _setupMessage(Message msg)
{
  try
  {
    String username = _account.getUsername();
    String from = username + "@" + _account.getDomain();
    List<InternetAddress> to = _getEmailList(getTo());
    
    List<InternetAddress> cc = null;
    String ccString = getCc();
    if(ccString != null) 
    {
      cc = _getEmailList(ccString);  
    }
    
    msg.setFrom(new InternetAddress(from));
    if ((to != null) && !to.isEmpty())
      msg.setRecipients(Message.RecipientType.TO,
                        to.toArray(new InternetAddress[0]));

    if ((cc != null) && !cc.isEmpty())
      msg.setRecipients(Message.RecipientType.CC,
                        cc.toArray(new InternetAddress[0]));
    msg.setSubject(_subject == null ? "" : _subject);
    if ((_attachment1 == null) &&
        (_attachment2 == null) &&
        (_attachment3 == null))
    {
      msg.setText(_content == null ? "" : _content);
    }
    // Multipart.
    else
    {
      // Create the message part
      BodyPart messageBodyPart = new MimeBodyPart();

      // Fill the message
      messageBodyPart.setText(_content == null ? "" : _content);

      Multipart multipart = new MimeMultipart();
      multipart.addBodyPart(messageBodyPart);

      if (_attachment1 != null)
        _addAttachment(multipart, _attachment1);
      if (_attachment2 != null)
        _addAttachment(multipart, _attachment2);
      if (_attachment3 != null)
        _addAttachment(multipart, _attachment3);

      // Put all the parts in the message
      msg.setContent(multipart);
    }

    String mailer = "OracleAdfEmailDemo";
    msg.setHeader("X-Mailer", mailer);
    msg.setSentDate(new Date());

    return msg;
  }
  catch(AddressException ae)
  {
     _showSendException(ae);
  }
  catch(MessagingException me)
  {
    _showSendException(me);
  }
  catch(Exception e)
  {
    _showSendException(e);
  }

  return null;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:78,代码来源:NewMessageBackingBean.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: 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

示例12: 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

示例13: send

import javax.mail.Message; //导入方法依赖的package包/类
public void send ( final String subject, final String text ) throws MessagingException
{
    final Message message = new MimeMessage ( this.session );

    if ( this.from != null )
    {
        message.setFrom ( this.from );
    }
    else
    {
        message.setFrom ();
    }

    message.setHeader ( "Return-Path", "<>" );

    message.setRecipients ( javax.mail.Message.RecipientType.TO, this.to );
    message.setSubject ( subject );
    message.setText ( text );

    message.saveChanges ();

    final Transport transport = this.session.getTransport ();
    logger.debug ( "Connecting transport..." );
    transport.connect ();
    logger.debug ( "Connecting transport... done!" );
    try
    {
        logger.debug ( "Sending message..." );
        transport.sendMessage ( message, message.getAllRecipients () );
        logger.debug ( "Sending message... done!" );
    }
    finally
    {
        logger.debug ( "Closing transport..." );
        try
        {
            transport.close ();
            logger.debug ( "Closing transport... done!" );
        }
        catch ( final Exception e )
        {
            logger.info ( "Failed to close transport", e );
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:46,代码来源:MailSender.java

示例14: sendMail

import javax.mail.Message; //导入方法依赖的package包/类
public boolean sendMail(String to,String otp) throws MessagingException 
{
	String host="smtp.gmail.com";
	String username="";//emailid
	String password="";//emailid password
	String from=" ";// email from which u have to send
	String subject="One Time Password";
	String body="Your One Time passsword is "+otp;
	
	boolean sessionDebug=false;
	
	Properties props=System.getProperties();
	props.put("mail.host",host);
	props.put("mail.transport.protocol","smtp");
	props.put("mail.smtp.starttls.enable","true");
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.debug", "true");
	props.put("mail.smtp.socketFactory.port", "465");
	props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
	props.put("mail.smtp.socketFactory.fallback", "false");
	props.put("mail.smtp.host", "smtp.gmail.com");
	props.put("mail.smtp.port", "25"); 
	
	Session mailSession=Session.getDefaultInstance(props,null);
	mailSession.setDebug(sessionDebug);
	
	Message msg=new MimeMessage(mailSession);
	msg.setFrom(new InternetAddress(from));
	InternetAddress [] address={new InternetAddress(to)};
	msg.setRecipients(Message.RecipientType.TO,address);
	msg.setSubject(subject);
	msg.setSentDate(new Date());
	msg.setText(body);

	Transport tr=mailSession.getTransport("smtp");
	tr.connect(host,username,password);
	msg.saveChanges();
	tr.sendMessage(msg,msg.getAllRecipients());
	tr.close();
	//Transport.send(msg);
	return true;
}
 
开发者ID:nishittated,项目名称:OnlineElectionVotingSystem,代码行数:43,代码来源:PasswordMail.java

示例15: sendMail1

import javax.mail.Message; //导入方法依赖的package包/类
public boolean sendMail1(String to,String passwrd, String link) throws MessagingException
{
	String host="smtp.gmail.com";
	String username="	 ";//emailid
	String password="";//emailid password
	String from=" ";// email from which u have to send
	String subject="Website Password";
	String body="Your website password is "+passwrd+"  Please click to reset "+link;
	boolean sessionDebug=false;
	
	Properties props=System.getProperties();
	props.put("mail.host",host);
	props.put("mail.transport.protocol","smtp");
	props.put("mail.smtp.starttls.enable","true");
	props.put("mail.smtp.auth", "true");
	props.put("mail.smtp.debug", "true");
	props.put("mail.smtp.socketFactory.port", "465");
	props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
	props.put("mail.smtp.socketFactory.fallback", "false");
	props.put("mail.smtp.host", "smtp.gmail.com");
	props.put("mail.smtp.port", "25"); 
	
	Session mailSession=Session.getDefaultInstance(props,null);
	mailSession.setDebug(sessionDebug);

	Message msg=new MimeMessage(mailSession);
	msg.setFrom(new InternetAddress(from));
	
	InternetAddress [] address={new InternetAddress(to)};
	msg.setRecipients(Message.RecipientType.TO,address);
	msg.setSubject(subject);
	msg.setSentDate(new Date());
	msg.setText(body);
	
	Transport tr=mailSession.getTransport("smtp");
	tr.connect(host,username,password);
	msg.saveChanges();
	tr.sendMessage(msg,msg.getAllRecipients());
	tr.close();
			//Transport.send(msg);
	return true;
}
 
开发者ID:nishittated,项目名称:OnlineElectionVotingSystem,代码行数:43,代码来源:PasswordMail.java


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