本文整理匯總了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);
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}