當前位置: 首頁>>代碼示例>>Java>>正文


Java MimeMessage.addRecipient方法代碼示例

本文整理匯總了Java中javax.mail.internet.MimeMessage.addRecipient方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeMessage.addRecipient方法的具體用法?Java MimeMessage.addRecipient怎麽用?Java MimeMessage.addRecipient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.internet.MimeMessage的用法示例。


在下文中一共展示了MimeMessage.addRecipient方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: completeClientSend

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public void completeClientSend(String mailServer, String... credentials) throws AddressException, MessagingException {
	if (credentials != null && credentials.length > 1) {
		// Step1
		logger.info("\n 1st ===> setup Mail Server Properties..");
		logger.info("Mail Server Properties have been setup successfully..");
		// Step2
		logger.info("\n\n 2nd ===> get Mail .");
		getMailSession = getDefaultInstance(mailServerProperties, null);
		generateMailMessage = new MimeMessage(getMailSession);
		generateMailMessage.addRecipient(TO, new InternetAddress("[email protected]"));
		generateMailMessage.addRecipient(CC, new InternetAddress("[email protected]"));
		generateMailMessage.setSubject("Greetings from Vige..");
		String emailBody = "Test email by Vige.it JavaMail API example. " + "<br><br> Regards, <br>Vige Admin";
		generateMailMessage.setContent(emailBody, "text/html");
		logger.info("Mail Session has been created successfully..");
		// Step3
		logger.info("\n\n 3rd ===> Get Session and Send mail");
		Transport transport = getMailSession.getTransport("smtp");
		// Enter your correct gmail UserID and Password
		// if you have 2FA enabled then provide App Specific Password
		transport.connect(mailServer, credentials[0], credentials[1]);
		transport.sendMessage(generateMailMessage, generateMailMessage.getAllRecipients());
		transport.close();
	}
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:26,代碼來源:SendMail.java

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

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

示例4: sendTokenMail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
@Override
public boolean sendTokenMail(final String[] to, final String contractAddress, final String artifactId,
                             final String registryContract) {
    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(TOKEN_SUBJECT);
        message.setText(tokenBody + contractAddress + "\nArtifact ID: " + artifactId
                + "\n\nBelow is the Unilog Registry. Add this into the verifiers portal if you need to"
                + " verify a token: \n" + registryContract);
        Transport transport = session.getTransport("smtp");
        transport.connect(host, username, password);
        transport.sendMessage(message, message.getAllRecipients());
        transport.close();
        LOGGER.info("Token email has been sent");
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
開發者ID:blmalone,項目名稱:Blockchain-Academic-Verification-Service,代碼行數:34,代碼來源:EmailService.java

示例5: sendMultipartMessage

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public void sendMultipartMessage(String subject, String[] to, String text, String attach)
    throws MessagingException, IOException {
   
    MimeMessage message = new MimeMessage(senderSession);
    message.setFrom(new InternetAddress(pManager.get_SENDER_From())); // FROM
    
    for(int i=0; i < to.length; i++) {
        if(!to[i].equals("")) {
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to[i])); // TO
        }
    }
    
    message.setSubject(subject); //SUBJECT
    
    Multipart mp = new MimeMultipart();
    
    BodyPart textPart = new MimeBodyPart();
    textPart.setText(text);
    mp.addBodyPart(textPart);  // TEXT
    
    MimeBodyPart attachPart = new MimeBodyPart();
    attachPart.attachFile(attach);
    mp.addBodyPart(attachPart); // ATTACH
    
    message.setContent(mp);
    transport.sendMessage(message, message.getAllRecipients());
}
 
開發者ID:adbenitez,項目名稱:MailCopier,代碼行數:28,代碼來源:MailCopier.java

示例6: createEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private 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);
	email.setFrom(new InternetAddress(from));
	email.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
	email.setSubject(subject);
	email.setText(bodyText);
	return email;
}
 
開發者ID:tburne,項目名稱:blog-examples,代碼行數:11,代碼來源:ClientRequestAPI.java

示例7: sendAccountActiveEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/** 發送用戶驗證的郵件 */
public static void sendAccountActiveEmail(User user) {

	String subject = "sdudoc郵箱驗證提醒";
	String content = "感謝您於" + DocUtil.getDateTime() + "在sdudoc注冊,複製以下鏈接,即可完成安全驗證:"
			+ "http://127.0.0.1:8080/sdudoc/activeUser.action?user.username=" + user.getUsername()
			+ "&user.checkCode=" + user.getCheckCode() + " 為保障您的帳號安全,請在24小時內點擊該鏈接,您也可以將鏈接複製到瀏覽器地址欄訪問。"
			+ "若您沒有申請過驗證郵箱 ,請您忽略此郵件,由此給您帶來的不便請諒解。";

	// session.setDebug(true);

	String from = "[email protected]"; // 發郵件的出發地(發件人的信箱)
	Session session = getMailSession();
	// 定義message
	MimeMessage message = new MimeMessage(session);
	try {
		// 設定發送郵件的地址
		message.setFrom(new InternetAddress(from));
		// 設定接受郵件的地址
		message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
		// 設定郵件主題
		message.setSubject(subject);
		// 設定郵件內容
		BodyPart mdp = new MimeBodyPart();// 新建一個存放信件內容的BodyPart對象
		mdp.setContent(content, "text/html;charset=utf8");// 給BodyPart對象設置內容和格式/編碼方式
		Multipart mm = new MimeMultipart();// 新建一個MimeMultipart對象用來存放BodyPart對
		// 象(事實上可以存放多個)
		mm.addBodyPart(mdp);// 將BodyPart加入到MimeMultipart對象中(可以加入多個BodyPart)
		message.setContent(mm);// 把mm作為消息對象的內容
		// message.setText(content);
		message.saveChanges();
		Transport.send(message);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:zhangjikai,項目名稱:sdudoc,代碼行數:37,代碼來源:MailUtil.java

示例8: sendResetPasswordEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/** 發送密碼重置的郵件 */
public static void sendResetPasswordEmail(User user) {
	String subject = "sdudoc密碼重置提醒";
	String content = "您於" + DocUtil.getDateTime() + "在sdudoc找回密碼,點擊以下鏈接,進行密碼重置:"
			+ "http://127.0.0.1:8080/sdudoc/resetPasswordCheck.action?user.username=" + user.getUsername()
			+ "&user.checkCode=" + user.getCheckCode() + " 為保障您的帳號安全,請在24小時內點擊該鏈接,您也可以將鏈接複製到瀏覽器地址欄訪問。"
			+ "若您沒有申請密碼重置,請您忽略此郵件,由此給您帶來的不便請諒解。";

	// session.setDebug(true);

	String from = "[email protected]"; // 發郵件的出發地(發件人的信箱)
	Session session = getMailSession();
	// 定義message
	MimeMessage message = new MimeMessage(session);
	try {
		message.setFrom(new InternetAddress(from));
		message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
		message.setSubject(subject);
		BodyPart mdp = new MimeBodyPart();
		mdp.setContent(content, "text/html;charset=utf8");
		Multipart mm = new MimeMultipart();
		mm.addBodyPart(mdp);
		message.setContent(mm);
		message.saveChanges();
		Transport.send(message);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:zhangjikai,項目名稱:sdudoc,代碼行數:30,代碼來源:MailUtil.java

示例9: sendAlertEmail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public void sendAlertEmail(String alert) throws MessagingException{
	String host = "smtp.gmail.com";
	String from = "[email protected]";
	String pass = "3inst3in?";
	Properties props = System.getProperties();
	props.put("mail.smtp.starttls.enable", "true"); // added this line
	props.put("mail.smtp.host", host);
	props.put("mail.smtp.user", from);
	props.put("mail.smtp.password", pass);
	props.put("mail.smtp.port", "587");
	props.put("mail.smtp.auth", "true");

	Session session = Session.getDefaultInstance(props, null);
	MimeMessage message = new MimeMessage(session);
	message.setFrom(new InternetAddress(from));

	InternetAddress[] toAddress = new InternetAddress[alert_recipients.length];

	// To get the array of addresses
	for( int i=0; i < alert_recipients.length; i++ ) { // changed from a while loop
		toAddress[i] = new InternetAddress(alert_recipients[i]);
	}
	//System.out.println(Message.RecipientType.TO);

	for( int i=0; i < toAddress.length; i++) { // changed from a while loop
		message.addRecipient(Message.RecipientType.TO, toAddress[i]);
	}
	message.setSubject("WARNING Something went wrong in the Einstein tunnel");
	message.setText(alert);
	Transport transport = session.getTransport("smtp");
	transport.connect(host, from, pass);
	transport.sendMessage(message, message.getAllRecipients());
	transport.close();

}
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:36,代碼來源:Resetter.java

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

示例11: createEmailWithAttachment

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public static MimeMessage createEmailWithAttachment(String to, String from, String subject,
                                      String bodyText,String filePath) throws MessagingException{
    File file = new File(filePath);
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);
    MimeMessage email = new MimeMessage(session);
    Multipart multipart = new MimeMultipart();
    InternetAddress tAddress = new InternetAddress(to);
    InternetAddress fAddress = new InternetAddress(from);
    email.setFrom(fAddress);
    email.addRecipient(javax.mail.Message.RecipientType.TO, tAddress);
    email.setSubject(subject);
    if (file.exists()) {
        source = new FileDataSource(filePath);
        messageFilePart = new MimeBodyPart();
        messageBodyPart = new MimeBodyPart();
        try {
            messageBodyPart.setText(bodyText);
            messageFilePart.setDataHandler(new DataHandler(source));
            messageFilePart.setFileName(file.getName());

            multipart.addBodyPart(messageBodyPart);
            multipart.addBodyPart(messageFilePart);
            email.setContent(multipart);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }else
        email.setText(bodyText);
    return email;
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:32,代碼來源:EmailShield.java

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

示例13: sendMail

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public void sendMail(String to, String title, String content) throws MessagingException {
    Session session = Session.getDefaultInstance(properties, new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    });
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(fromAddress));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject(title);
    message.setContent(content, "text/html;charset=UTF-8");
    Transport.send(message);
}
 
開發者ID:superkoh,項目名稱:k-framework,代碼行數:15,代碼來源:JavaMailMessage.java

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

示例15: obtenerMailEmisor

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public static void enviarMailCumpleaños(Cliente cliente) {
	if (cliente.getPersonaMail() != null) {
		Mail mail = obtenerMailEmisor();
		Properties props = conectarse(mail);
		Session session = autentificar(mail, props);

		String asunto = "Feliz Cumpleaños " + cliente.getClienteNombre() + "!!!";

		String mensaje = "Queremos saludarlo en el mes de su cumpleaños, "
				+ "espero que tenga una gran celebración y un día maravilloso.\r\n\r\nFeliz cumpleaños "
				+ cliente.getClienteNombre() + ".\r\nDe parte del equipo de Pacinetes S.R.L.";

		try {
			BodyPart texto = new MimeBodyPart();

			// Texto del mensaje
			texto.setText(mensaje);

			MimeMultipart multiParte = new MimeMultipart();
			multiParte.addBodyPart(texto);

			MimeMessage message = new MimeMessage(session);

			// Se rellena el From
			InternetAddress emisor = new InternetAddress(mail.getNombre() + " <" + mail.getMail() + ">");
			message.setFrom(emisor);

			// Se rellenan los destinatarios
			InternetAddress receptor = new InternetAddress();
			receptor.setAddress(cliente.getPersonaMail());
			message.addRecipient(Message.RecipientType.TO, receptor);

			// Se rellena el subject
			message.setSubject(asunto);

			// Se mete el texto y la foto adjunta.
			message.setContent(multiParte);

			Transport.send(message);

		} catch (MessagingException e) {
			messageService.informUser("Poliza creada, falló envío de mail");
		}

	}
}
 
開發者ID:leandrogonqn,項目名稱:Proyecto2017Seguros,代碼行數:47,代碼來源:Mail.java


注:本文中的javax.mail.internet.MimeMessage.addRecipient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。