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