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


Java MimeMessage.setText方法代码示例

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


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

示例1: sendTextEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public static void sendTextEmail(String to, String from, String subject, String msg, final ServerSetup setup) {
    try {
        Session session = getSession(setup);

        Address[] tos = new javax.mail.Address[0];
        tos = new InternetAddress[]{new InternetAddress(to)};
        Address[] froms = new InternetAddress[]{new InternetAddress(from)};
        MimeMessage mimeMessage = new MimeMessage(session);
        mimeMessage.setSubject(subject);
        mimeMessage.setFrom(froms[0]);

        mimeMessage.setText(msg);
        Transport.send(mimeMessage, tos);
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-greenmail,代码行数:18,代码来源:GreenMailUtil.java

示例2: sendEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
private static void sendEmail(String fromEmail, String toEmail, String subject, String body, boolean html)
throws MessagingException{
	MimeMessage message = new MimeMessage(MAILING_SESSION);
	message.setFrom(new InternetAddress(fromEmail));
	InternetAddress[] addresses = InternetAddress.parse(toEmail);//one or more addresses
	message.addRecipients(RecipientType.TO, addresses);
	message.setReplyTo(addresses);
	message.setSubject(subject);
	String subType;
	if(html){
		subType = "html";
	}else{
		subType = "plain";
	}
	message.setText(body, "UTF-8", subType);
	Transport.send(message);
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:18,代码来源:DatarouterEmailTool.java

示例3: sendEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
@Override
public void sendEmail(String address, String subject, String content, Map<String, String> headers) throws Exception {
	Session session = MailUtilities.makeSession();
	if (session == null) {
		// LogService.getRoot().warning("Unable to create mail session. Not sending mail to "+address+".");
		LogService.getRoot().log(Level.WARNING, "com.rapidminer.tools.MailSenderSMTP.creating_mail_session_error",
				address);
	}
	MimeMessage msg = new MimeMessage(session);
	msg.setRecipients(Message.RecipientType.TO, address);
	msg.setFrom();
	msg.setSubject(subject, "UTF-8");
	msg.setSentDate(new Date());
	msg.setText(content, "UTF-8");

	if (headers != null) {
		for (Entry<String, String> header : headers.entrySet()) {
			msg.setHeader(header.getKey(), header.getValue());
		}
	}
	Transport.send(msg);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:23,代码来源:MailSenderSMTP.java

示例4: sendToAdmin

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
@Override
public boolean sendToAdmin(final String institutionEmailAddress, final String applicationMessage) {
    String[] to = new String[]{"[email protected]"};
    setupProperties();
    Session session = Session.getDefaultInstance(properties);
    MimeMessage message = new MimeMessage(session);
    try {
        message.setFrom(new InternetAddress(username));
        InternetAddress[] toAddress = new InternetAddress[to.length];

        // To get the array of addresses
        for (int i = 0; i < to.length; i++) {
            toAddress[i] = new InternetAddress(to[i]);
        }

        for (int i = 0; i < toAddress.length; i++) {
            message.addRecipient(Message.RecipientType.TO, toAddress[i]);
        }
        message.setSubject(APPLICATION_SUBJECT);
        message.setText(applicationBody + "Email: " + institutionEmailAddress + "\nMessage: " + applicationMessage);
        Transport transport = session.getTransport("smtp");
        transport.connect(host, username, password);
        transport.sendMessage(message, message.getAllRecipients());
        transport.close();
        LOGGER.info("Email sent to Admin");
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:blmalone,项目名称:Blockchain-Academic-Verification-Service,代码行数:32,代码来源:EmailService.java

示例5: sendMail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public String sendMail() {
	
	mail.setPassword(Mailer.PA);
	mail.setHost(Mailer.HOST);
	mail.setSender(Mailer.SENDER);
	Properties properties = System.getProperties();
	properties.put("mail.smtp.host", mail.getHost());
	properties.put("mail.smtp.auth", "true");
	properties.put("mail.smtp.socketFactory.port", "465");    
       properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");     
       properties.put("mail.smtp.port", "465");    
	Session session = Session.getInstance(properties,
			new javax.mail.Authenticator() {
				protected PasswordAuthentication getPasswordAurhentication() {
					return new PasswordAuthentication(mail.getSender(), mail.getPassword());
				}
			});
	
	try {
		
		MimeMessage message = new MimeMessage(session);
		message.setFrom(new InternetAddress(mail.getSender()));
		message.addRecipient(Message.RecipientType.TO, new InternetAddress(mail.getEmailId()));
		message.setSubject(mail.getSubject());
		message.setText(mail.getMessage());
		Transport.send(message, mail.getSender(),mail.getPassword());
		System.out.println("Mail Sent");
		return StatusCode.SUCCESS;
	} catch(Exception ex) {
		throw new RuntimeException("Error while sending mail" + ex);
	}
}
 
开发者ID:vishal1997,项目名称:DiscussionPortal,代码行数:33,代码来源:SendMail.java

示例6: sendEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
private Boolean sendEmail(String randomKey, UserEntity userEntity) {
	try {
		MimeMessage message = new MimeMessage(mailSession);
		message.setFrom(new InternetAddress(Config.getEmailFrom()));
		message.addRecipient(Message.RecipientType.TO, new InternetAddress(userEntity.getEmail()));
		message.setSubject("Recovery Password Email");
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append("Dear user,\n\n");
		stringBuilder.append("Someone requested to recover forgotten password in our soapbox race world server.\n\n");
		stringBuilder.append("If wasn't you, just ignore this email.\n\n");
		stringBuilder.append("You can click this link to reset your password:\n\n");
		stringBuilder.append(Config.getServerAddress());
		stringBuilder.append("/soapbox-race-core/password.jsp?randomKey=");
		stringBuilder.append(randomKey);
		stringBuilder.append("\n\nThanks for playing!\n\n");
		stringBuilder.append("\n\nSBRW Team.\n");
		message.setText(stringBuilder.toString());
		Transport.send(message);
		return true;
	} catch (MessagingException mex) {
		mex.printStackTrace();
		return false;
	}
}
 
开发者ID:SoapboxRaceWorld,项目名称:soapbox-race-core,代码行数:25,代码来源:RecoveryPasswordBO.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: sendAccountCreatedMail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
@Override
public boolean sendAccountCreatedMail(final String[] to, final String email) {
    setupProperties();
    Session session = Session.getDefaultInstance(properties);
    MimeMessage message = new MimeMessage(session);
    try {
        message.setFrom(new InternetAddress(username));
        InternetAddress[] toAddress = new InternetAddress[to.length];

        // To get the array of addresses
        for (int i = 0; i < to.length; i++) {
            toAddress[i] = new InternetAddress(to[i]);
        }

        for (int i = 0; i < toAddress.length; i++) {
            message.addRecipient(Message.RecipientType.TO, toAddress[i]);
        }
        message.setSubject(DETAILS_SUBJECT);
        message.setText(detailsBody + "username: " + email);
        Transport transport = session.getTransport("smtp");
        transport.connect(host, username, password);
        transport.sendMessage(message, message.getAllRecipients());
        transport.close();
        LOGGER.info("Login details email has been sent.");
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:blmalone,项目名称:Blockchain-Academic-Verification-Service,代码行数:31,代码来源:EmailService.java

示例9: createMimeMessage

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
private MimeMessage createMimeMessage(String from, String subject, String body, Date date) throws AddressException, MessagingException {
    MimeMessage msg = new MimeMessage(greenMail.getSmtp().createSession());
    msg.setFrom(new InternetAddress(from));
    msg.addRecipient(Message.RecipientType.TO,
            new InternetAddress(TEST_RECIP));
    msg.setSubject(subject);
    msg.setText(body);
    msg.setSentDate(date != null ? date : new Date());
    return msg;
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:11,代码来源:TestMailUtil.java

示例10: setMimeMessageContent

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
protected void setMimeMessageContent(MimeMessage mimeMessage, MailInfo mailInfo) 
    throws MessagingException {
    if (mailInfo.getContentType() == null) {
        mimeMessage.setText(mailInfo.getMessage());
    } else {
        mimeMessage.setContent(mailInfo.getMessage(), mailInfo.getContentType());
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:9,代码来源:SendMailJob.java

示例11: createEmail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public static MimeMessage createEmail(String to, String from, String subject,
                                      String bodyText) throws MessagingException{
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);
    MimeMessage email = new MimeMessage(session);
    InternetAddress tAddress = new InternetAddress(to);
    InternetAddress fAddress = new InternetAddress(from);
    email.setFrom(fAddress);
    email.addRecipient(javax.mail.Message.RecipientType.TO, tAddress);
    email.setSubject(subject);
    email.setText(bodyText);
    return email;
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:14,代码来源:EmailShield.java

示例12: sendSetupMail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
@Override
public boolean sendSetupMail(final String[] to, final String code, final String subject, final String body) {
    setupProperties();
    Session session = Session.getDefaultInstance(properties);
    MimeMessage message = new MimeMessage(session);
    try {
        message.setFrom(new InternetAddress(username));
        InternetAddress[] toAddress = new InternetAddress[to.length];

        // To get the array of addresses
        for (int i = 0; i < to.length; i++) {
            toAddress[i] = new InternetAddress(to[i]);
        }

        for (int i = 0; i < toAddress.length; i++) {
            message.addRecipient(Message.RecipientType.TO, toAddress[i]);
        }
        if (subject == null || body == null) {
            message.setSubject(SETUP_SUBJECT);
            message.setText(setupBody + code);
        } else {
            message.setSubject(subject);
            message.setText(body + code);
        }

        Transport transport = session.getTransport("smtp");
        transport.connect(host, username, password);
        transport.sendMessage(message, message.getAllRecipients());
        transport.close();
        LOGGER.info("Setup email has been sent.");
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:blmalone,项目名称:Blockchain-Academic-Verification-Service,代码行数:37,代码来源:EmailService.java

示例13: sendMail

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
 *  Send the mail
 *
 * @param  aMailhost mail server
 * @param  aFrom from address
 * @param  aToList comma-separated recipient list
 * @param  aSubject mail subject
 * @param  aText mail body
 * @throws Exception if sending message fails
 */
private void sendMail(String aMailhost, String aFrom, String aToList,
        String aSubject, String aText)
    throws Exception
{
    // Get system properties
    final Properties props = System.getProperties();

    // Setup mail server
    props.put("mail.smtp.host", aMailhost);

    // Get session
    final Session session = Session.getDefaultInstance(props, null);

    // Define message
    final MimeMessage message = new MimeMessage(session);

    message.setFrom(new InternetAddress(aFrom));
    final StringTokenizer t = new StringTokenizer(aToList, ", ", false);
    while (t.hasMoreTokens()) {
        message.addRecipient(
            MimeMessage.RecipientType.TO,
            new InternetAddress(t.nextToken()));
    }
    message.setSubject(aSubject);
    message.setText(aText);

    Transport.send(message);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:39,代码来源:MailLogger.java

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

示例15: send

import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public void send(String email, String token) throws EmailException {
	Properties properties = System.getProperties();

	properties.put("mail.smtp.auth", "true");
	properties.put("mail.smtp.starttls.enable", "true");
	properties.put("mail.smtp.host", emailProperties.getSmtpHost());
	properties.put("mail.smtp.port", emailProperties.getSmtpPort());

	Session session = Session.getInstance(properties, new Authenticator() {
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(emailProperties.getUsername(), emailProperties.getPassword());
		}
	});

	try {
		MimeMessage message = new MimeMessage(session);

		message.setFrom(new InternetAddress(emailProperties.getUsername()));
		message.addRecipient(Message.RecipientType.TO, new InternetAddress(email));

		message.setSubject(messages.getMessageBy("label.pathological.reports").concat(" - ").concat(messages.getMessageBy("label.recover.password")));
		message.setText(createBody(emailProperties.getApplicationCtxPath(), token));

		Transport.send(message);
	} catch (MessagingException mex) {
		mex.printStackTrace();
		throw new EmailException(messages.getMessageBy("message.email.exception"));
	}
}
 
开发者ID:edylle,项目名称:pathological-reports,代码行数:30,代码来源:EmailService.java


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