本文整理汇总了Java中javax.mail.internet.InternetAddress类的典型用法代码示例。如果您正苦于以下问题:Java InternetAddress类的具体用法?Java InternetAddress怎么用?Java InternetAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InternetAddress类属于javax.mail.internet包,在下文中一共展示了InternetAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: completeClientSend
import javax.mail.internet.InternetAddress; //导入依赖的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();
}
}
示例2: createMimeMessage
import javax.mail.internet.InternetAddress; //导入依赖的package包/类
/**
*
* @param session 和服务器交互的会话
* @param mail 邮件内容
* @return
* @throws Exception
*/
private static MimeMessage createMimeMessage(Session session, String SendAccount, Mail mail) throws Exception {
MimeMessage message = new MimeMessage(session);
//From: 发件人
message.setFrom(new InternetAddress(SendAccount, mail.getPersonal(), "UTF-8"));
// To: 收件人
message.setRecipients(MimeMessage.RecipientType.TO, mail.getAddresses());
// Subject: 邮件主题
message.setSubject(mail.getSubject(), "UTF-8");
// Content: 邮件正文(可以使用html标签)
message.setContent(mail.getContext(), "text/html;charset=UTF-8");
// 设置发件时间
message.setSentDate(new Date());
message.saveChanges();
return message;
}
示例3: 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);
}
示例4: createCodeMessage
import javax.mail.internet.InternetAddress; //导入依赖的package包/类
/**
* 创建一封邮件
*
* @param session 和服务器交互的会话
* @param sendMail 发件人邮箱
* @param receiveMail 收件人邮箱
* @return
* @throws Exception
*/
private MimeMessage createCodeMessage(Session session, String sendMail, String receiveMail) throws MessagingException, UnsupportedEncodingException {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(sendMail, "吃在华科", "UTF-8"));
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, this.name, "UTF-8"));
message.setSubject("吃在华科邮件注册验证码", "UTF-8");
String content = this.name + ",你好, 您的验证码如下<br/>" + getCode() + "<p> 您不需要回复这封邮件。<p/>";
message.setContent(content, "text/html;charset=UTF-8");
message.setSentDate(new Date());
message.saveChanges();
return message;
}
示例5: test_cr948_addSecurityGroupWatcher
import javax.mail.internet.InternetAddress; //导入依赖的package包/类
/**
* Tests add security groups as build watchers
*/
public void test_cr948_addSecurityGroupWatcher() throws AddressException {
// make test watcher list
final String TEST_VALID_WATCHER_GROUP_NAME = "Test group 1";
final List watchers = new ArrayList(1);
watchers.add(new BuildWatcher(TEST_VALID_WATCHER_GROUP_NAME, BuildWatcher.LEVEL_SYSTEM_ERROR));
composer.addWatchers(BuildWatcher.LEVEL_BROKEN, watchers);
// make recipients
boolean emailFromGroupUserFound = false;
final EmailRecipients recipients = composer.makeRecipients(cm.getBuildRun(3), new HashMap(), false, true, false, true, BuildWatcher.LEVEL_BROKEN);
for (final Iterator i = recipients.getAllAddresses().iterator(); i.hasNext();) {
final String address = ((InternetAddress) i.next()).getAddress();
emailFromGroupUserFound = emailFromGroupUserFound || address.equals("[email protected]");
}
assertTrue(emailFromGroupUserFound);
}
示例6: sendAttachMail
import javax.mail.internet.InternetAddress; //导入依赖的package包/类
public boolean sendAttachMail(MailSenderInfo mailInfo) {
MyAuthenticator authenticator = null;
Properties pro = mailInfo.getProperties();
if (mailInfo.isValidate()) {
authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
}
try {
Message mailMessage = new MimeMessage(Session.getInstance(pro, authenticator));
mailMessage.setFrom(new InternetAddress(mailInfo.getFromAddress()));
mailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(mailInfo.getToAddress()));
mailMessage.setSubject(mailInfo.getSubject());
mailMessage.setSentDate(new Date());
Multipart multi = new MimeMultipart();
BodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setContent(mailInfo.getContent(), "text/html; charset=utf-8");
multi.addBodyPart(textBodyPart);
for (String path : mailInfo.getAttachFileNames()) {
DataSource fds = new FileDataSource(path);
BodyPart fileBodyPart = new MimeBodyPart();
fileBodyPart.setDataHandler(new DataHandler(fds));
fileBodyPart.setFileName(path.substring(path.lastIndexOf("/") + 1));
multi.addBodyPart(fileBodyPart);
}
mailMessage.setContent(multi);
mailMessage.saveChanges();
Transport.send(mailMessage);
return true;
} catch (MessagingException ex) {
ex.printStackTrace();
return false;
}
}
示例7: setFrom
import javax.mail.internet.InternetAddress; //导入依赖的package包/类
/**
* 设置发信人
*
* @param name String
* @param pass String
*/
public boolean setFrom(String from) {
if (from == null || from.trim().equals("")) {
from = PropertiesUtil.getString("email.send.from");
}
try {
String[] f = from.split(",");
if (f.length > 1) {
from = MimeUtility.encodeText(f[0]) + "<" + f[1] + ">";
}
mimeMsg.setFrom(new InternetAddress(from)); // 设置发信人
return true;
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return false;
}
}
示例8: getAdminAddresslList
import javax.mail.internet.InternetAddress; //导入依赖的package包/类
/**
* Returns a list of emails of admin users.
*
* @param addSystemAdminAddress tru if system admin should be added
* @return list of emails of admin users.
* @throws AddressException
* @throws UnsupportedEncodingException
*/
public static Collection getAdminAddresslList(final boolean addSystemAdminAddress) throws AddressException {
try {
// Add system admin email
final List result = new ArrayList(11);
if (addSystemAdminAddress) {
result.add(getSystemAdminAddress());
}
// Add all enabled admin users emails
final List adminUsers = SecurityManager.getInstance().getAdminUsers();
for (int i = 0; i < adminUsers.size(); i++) {
final User user = (User) adminUsers.get(i);
result.add(new InternetAddress(user.getEmail(), user.getFullName()));
}
return result;
} catch (UnsupportedEncodingException e) {
final AddressException ae = new AddressException(StringUtils.toString(e));
ae.initCause(e);
throw ae;
}
}
示例9: buildEmailMessage
import javax.mail.internet.InternetAddress; //导入依赖的package包/类
private Message buildEmailMessage(EmailInfo emailInfo)
throws AddressException, MessagingException, UnsupportedEncodingException {
MimeMessage message = new MimeMessage(this.session);
message.setFrom(new InternetAddress(emailInfo.getFrom(), "网页更新订阅系统", "UTF-8"));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(emailInfo.getTo()));
Multipart multipart = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(emailInfo.getContent(), "text/html;charset=UTF-8");
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
message.setSubject(emailInfo.getTitle());
message.saveChanges();
return message;
}
示例10: sendMail
import javax.mail.internet.InternetAddress; //导入依赖的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);
}
}
示例11: sendEmail
import javax.mail.internet.InternetAddress; //导入依赖的package包/类
private void sendEmail(TokenStoreEntity token, UserEntity user) {
Map<String, Object> params = new HashMap<>();
String subject;
String template;
if (TokenStoreType.USER_ACTIVATION.equals(token.getType())){
params.put("activationUrl", baseUrl + "/registration/activate?at=" + token.getToken());
subject = "Registration Confirmation";
template = "email/registration.html";
} else {
params.put("changepassUrl", baseUrl + "/changepass/update?rt=" + token.getToken());
subject = "Reset Password Confirmation";
template = "email/changepass.html";
}
try {
emailService.sendEmail(null, new InternetAddress(user.getEmail()), subject, params, template);
} catch (AddressException e) {
throw new RegistrationException("Unable to send activation link");
}
}
示例12: sendMessageOrderIsReady
import javax.mail.internet.InternetAddress; //导入依赖的package包/类
@Override
public void sendMessageOrderIsReady(String recipientEmail) {
System.out.println("Sending e-mail to "+recipientEmail);
Properties props = buildProperties();
Session session = Session.getInstance(props, buildAuthenticator());
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipientEmail));
message.setSubject("Package ready to fly");
message.setText("Your package is ready to fly!");
Transport.send(message);
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
示例13: 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);
}
}
示例14: setRecipient
import javax.mail.internet.InternetAddress; //导入依赖的package包/类
/**
* Set the To recipient of a mime package, the CC and BCC recipients are
* cleared
*
* @param address the email address of the recipient
* @throws PackageException
*/
@PublicAtsApi
public void setRecipient(
String address ) throws PackageException {
try {
// add the recipient
InternetAddress inetAddress = new InternetAddress(address);
message.setRecipients(javax.mail.internet.MimeMessage.RecipientType.TO,
new InternetAddress[]{ inetAddress });
message.setRecipients(javax.mail.internet.MimeMessage.RecipientType.CC,
new InternetAddress[]{});
message.setRecipients(javax.mail.internet.MimeMessage.RecipientType.BCC,
new InternetAddress[]{});
} catch (MessagingException me) {
throw new PackageException(me);
}
}
示例15: addRecipient
import javax.mail.internet.InternetAddress; //导入依赖的package包/类
/**
* Add recipients of a specified type
*
* @param type the recipients' type
* @param addresses the email addresses of the recipients
* @throws PackageException
*/
@PublicAtsApi
public void addRecipient(
RecipientType type,
String[] addresses ) throws PackageException {
try {
// add the recipient
InternetAddress[] address = new InternetAddress[addresses.length];
for (int i = 0; i < addresses.length; i++)
address[i] = new InternetAddress(addresses[i]);
message.addRecipients(type.toJavamailType(), address);
} catch (MessagingException me) {
throw new PackageException(me);
}
}