本文整理汇总了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();
}
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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());
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
}
示例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");
}
}
}