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


Java InternetAddress.parse方法代碼示例

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


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

示例1: sendEmail

import javax.mail.internet.InternetAddress; //導入方法依賴的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

示例2: setSenderName

import javax.mail.internet.InternetAddress; //導入方法依賴的package包/類
/**
 * Set the sender display name on the From header
 *
 * @param name
 *            the display name to set
 * @throws PackageException
 */
@PublicAtsApi
public void setSenderName(
                           String name ) throws PackageException {

    try {
        InternetAddress address = new InternetAddress();

        String[] fromHeaders = getHeaderValues(FROM_HEADER);
        if (fromHeaders != null && fromHeaders.length > 0) {

            // parse the from header if such exists
            String fromHeader = fromHeaders[0];
            if (fromHeader != null) {
                address = InternetAddress.parse(fromHeader)[0];
            }
        }

        address.setPersonal(name);
        message.setFrom(address);

    } catch (ArrayIndexOutOfBoundsException aioobe) {
        throw new PackageException("Sender not present");
    } catch (MessagingException me) {
        throw new PackageException(me);
    } catch (UnsupportedEncodingException uee) {
        throw new PackageException(uee);
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:36,代碼來源:MimePackage.java

示例3: main

import javax.mail.internet.InternetAddress; //導入方法依賴的package包/類
public static void main(String[] args) {
      Properties props = new Properties();
      /** Parâmetros de conexão com servidor Gmail */
      props.put("mail.smtp.host", "smtp.gmail.com");
      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() {
                       protected PasswordAuthentication getPasswordAuthentication() 
                       {
                             return new PasswordAuthentication("[email protected]", "tjm123456");
                       }
                  });
      /** Ativa Debug para sessão */
      session.setDebug(true);
      try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("[email protected]")); //Remetente

            Address[] toUser = InternetAddress //Destinatário(s)
                       .parse("[email protected]");  
            message.setRecipients(Message.RecipientType.TO, toUser);
            message.setSubject("Enviando email com JavaMail");//Assunto
            message.setText("Enviei este email utilizando JavaMail com minha conta GMail!");
            /**Método para enviar a mensagem criada*/
            Transport.send(message);
            System.out.println("Feito!!!");
       } catch (MessagingException e) {
            throw new RuntimeException(e);
      }
}
 
開發者ID:Ronneesley,項目名稱:redesocial,代碼行數:36,代碼來源:Enviar_email.java

示例4: parseAddress

import javax.mail.internet.InternetAddress; //導入方法依賴的package包/類
private List<InternetAddress> parseAddress(E event) {
    int len = toPatternLayoutList.size();

    List<InternetAddress> iaList = new ArrayList<InternetAddress>();

    for (int i = 0; i < len; i++) {
        try {
            PatternLayoutBase<E> emailPL = toPatternLayoutList.get(i);
            String emailAdrr = emailPL.doLayout(event);

            if ((emailAdrr == null) || (emailAdrr.length() == 0)) {
                continue;
            }

            InternetAddress[] tmp = InternetAddress.parse(emailAdrr, true);
            iaList.addAll(Arrays.asList(tmp));
        } catch (AddressException e) {
            addError("Could not parse email address for ["
                    + toPatternLayoutList.get(i) + "] for event [" + event
                    + "]", e);

            return iaList;
        }
    }

    return iaList;
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:28,代碼來源:SMTPAppenderBase.java

示例5: sendEmail

import javax.mail.internet.InternetAddress; //導入方法依賴的package包/類
public static void sendEmail(String host, String port,
        final String userName, final String password, String toAddress,
        String subject, String message, String nombreArchivoAdj, String urlArchivoAdj)
        		throws AddressException, MessagingException {
 
    // sets SMTP server properties
    Properties properties = new Properties();
    properties.put("mail.smtp.host", host);
    properties.put("mail.smtp.port", port);
    properties.put("mail.smtp.auth", "true");
    properties.put("mail.smtp.starttls.enable", "true");
 
    // creates a new session with an authenticator
    Authenticator auth = new Authenticator() {
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(userName, password);
        }
    };
 
    Session session = Session.getInstance(properties, auth);

    //Se crea la parte del cuerpo del mensaje.
    BodyPart texto = new MimeBodyPart();
    texto.setText(message);        
    BodyPart adjunto = new MimeBodyPart();
    
    if(nombreArchivoAdj != null ){	        
     adjunto.setDataHandler(new DataHandler(new FileDataSource(urlArchivoAdj)));
     adjunto.setFileName(nombreArchivoAdj);
    }
    
    //Juntar las dos partes
    MimeMultipart multiParte = new MimeMultipart();
    multiParte.addBodyPart(texto);
    if (nombreArchivoAdj != null) multiParte.addBodyPart(adjunto);
    
    // creates a new e-mail message
    Message msg = new MimeMessage(session);
 
    msg.setFrom(new InternetAddress(userName));
    InternetAddress[] toAddresses = null;
    toAddresses = InternetAddress.parse(toAddress, false);

    msg.setRecipients(Message.RecipientType.TO, toAddresses);
    msg.setSubject(subject);
    msg.setSentDate(new Date());
    //msg.setText(message);
    msg.setContent(multiParte);
 
    // sends the e-mail
    Transport.send(msg);       

}
 
開發者ID:stppy,項目名稱:spr,代碼行數:54,代碼來源:SendMail.java

示例6: parseAddress

import javax.mail.internet.InternetAddress; //導入方法依賴的package包/類
private InternetAddress parseAddress(String address) throws MessagingException {
	InternetAddress[] parsed = InternetAddress.parse(address);
	if (parsed.length != 1) {
		throw new AddressException("Illegal address", address);
	}
	InternetAddress raw = parsed[0];
	try {
		return (getEncoding() != null ?
				new InternetAddress(raw.getAddress(), raw.getPersonal(), getEncoding()) : raw);
	}
	catch (UnsupportedEncodingException ex) {
		throw new MessagingException("Failed to parse embedded personal name to correct encoding", ex);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:MimeMessageHelper.java

示例7: prepareMimeMessage

import javax.mail.internet.InternetAddress; //導入方法依賴的package包/類
protected MimeMessage prepareMimeMessage(MailInfo mailInfo)
    throws MessagingException {
    Session session = getMailSession(mailInfo);

    MimeMessage mimeMessage = new MimeMessage(session);

    Address[] toAddresses = InternetAddress.parse(mailInfo.getTo());
    mimeMessage.setRecipients(Message.RecipientType.TO, toAddresses);

    if (mailInfo.getCc() != null) {
        Address[] ccAddresses = InternetAddress.parse(mailInfo.getCc());
        mimeMessage.setRecipients(Message.RecipientType.CC, ccAddresses);
    }

    mimeMessage.setFrom(new InternetAddress(mailInfo.getFrom()));
    
    if (mailInfo.getReplyTo() != null) {
        mimeMessage.setReplyTo(new InternetAddress[]{new InternetAddress(mailInfo.getReplyTo())});
    }
    
    mimeMessage.setSubject(mailInfo.getSubject());
    
    mimeMessage.setSentDate(new Date());

    setMimeMessageContent(mimeMessage, mailInfo);

    return mimeMessage;
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:29,代碼來源:SendMailJob.java


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