本文整理汇总了Java中javax.mail.Message.setRecipients方法的典型用法代码示例。如果您正苦于以下问题:Java Message.setRecipients方法的具体用法?Java Message.setRecipients怎么用?Java Message.setRecipients使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.Message
的用法示例。
在下文中一共展示了Message.setRecipients方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMail
import javax.mail.Message; //导入方法依赖的package包/类
public static void sendMail(String host, int port, String username, String password, String recipients,
String subject, String content, String from) throws AddressException, MessagingException {
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", port);
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
message.setSubject(subject);
message.setText(content);
Transport.send(message);
}
示例2: sendEmailWithOrder
import javax.mail.Message; //导入方法依赖的package包/类
public static void sendEmailWithOrder(String text, String eMail, HttpServletRequest request) {
try {
Session session = EmailActions.authorizeWebShopEmail();
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(ApplicationProperties.SHOP_EMAIL));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(eMail, false));
msg.setSubject("Shop order");
msg.setText(text);
msg.setSentDate(new Date());
Transport.send(msg);
} catch (MessagingException e) {
System.out.println("Error : " + e);
}
}
示例3: sendTextEmail
import javax.mail.Message; //导入方法依赖的package包/类
/**
*
* @param recvEmail 收件人可多个,用","隔开
* @param title 标题
* @param text 邮件内容
*/
public static void sendTextEmail(String recvEmail, String title, String text) {
try {
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.qq.com");
props.setProperty("mail.smtp.auth", "true");
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.socketFactory.port", "994");
Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("463112653", "manllfvunnfwbjhh");
}
});
session.setDebug(true);
Message msg = new MimeMessage(session);
msg.setSubject(title);
msg.setText(text);
msg.setFrom(new InternetAddress("[email protected]"));
msg.setRecipients(RecipientType.TO, InternetAddress.parse(recvEmail));
msg.setRecipients(RecipientType.CC, InternetAddress.parse(recvEmail));
Transport.send(msg);
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: sendTextEmail
import javax.mail.Message; //导入方法依赖的package包/类
public static void sendTextEmail(String recvEmail) {
try {
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.qq.com");
props.setProperty("mail.smtp.auth", "true");
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.socketFactory.port", "994");
Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("463112653", "manllfvunnfwbjhh");
}
});
session.setDebug(true);
Message msg = new MimeMessage(session);
msg.setSubject("Hello Vme");
//整个邮件的MultiPart(不能直接加入内容,需要在bodyPart中加入)
Multipart emailPart = new MimeMultipart();
MimeBodyPart attr1 = new MimeBodyPart();
attr1.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/2601169057.png")));
attr1.setFileName("tip.pic");
MimeBodyPart attr2 = new MimeBodyPart();
attr2.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/1724836491.png")));
attr2.setFileName(MimeUtility.encodeText("哦图像"));
MimeBodyPart content = new MimeBodyPart();
MimeMultipart contentPart = new MimeMultipart();
MimeBodyPart imgPart = new MimeBodyPart();
imgPart.setDataHandler(new DataHandler(new FileDataSource("E:/workspaces/Archon/src/main/webapp/uploadfile/head_img/1724836491.png")));
imgPart.setContentID("pic");
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent("<h1><a href='www.baidu.com'>百度一下</a><img src='cid:pic'/></h1>", "text/html;charset=utf-8");
contentPart.addBodyPart(imgPart);
contentPart.addBodyPart(htmlPart);
content.setContent(contentPart);
emailPart.addBodyPart(attr1);
emailPart.addBodyPart(attr2);
emailPart.addBodyPart(content);
msg.setContent(emailPart);
msg.setFrom(new InternetAddress("[email protected]"));
msg.setRecipients(RecipientType.TO, InternetAddress.parse("[email protected],[email protected]"));
msg.setRecipients(RecipientType.CC, InternetAddress.parse("[email protected],[email protected]"));
Transport.send(msg);
} catch (Exception e) {
e.printStackTrace();
}
}
示例5: sendHtmlMail
import javax.mail.Message; //导入方法依赖的package包/类
public boolean sendHtmlMail(MailSenderInfo mailInfo) {
XLog.d("发送网页版邮件!");
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()));
String[] receivers = mailInfo.getReceivers();
Address[] tos = new InternetAddress[receivers.length];
for (int i = 0; i < receivers.length; i++) {
tos[i] = new InternetAddress(receivers[i]);
}
mailMessage.setRecipients(Message.RecipientType.TO, tos);
mailMessage.setSubject(mailInfo.getSubject());
mailMessage.setSentDate(new Date());
Multipart mainPart = new MimeMultipart();
BodyPart html = new MimeBodyPart();
html.setContent(mailInfo.getContent(), "text/html; charset=utf-8");
mainPart.addBodyPart(html);
mailMessage.setContent(mainPart);
Transport.send(mailMessage);
return true;
} catch (MessagingException ex) {
ex.printStackTrace();
return false;
}
}
示例6: main
import javax.mail.Message; //导入方法依赖的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);
}
}
示例7: sendMail
import javax.mail.Message; //导入方法依赖的package包/类
/**
* 发邮件处理
*
* @param toAddr
* 邮件地址
* @param content
* 邮件内容
* @return 成功标识
*/
public static boolean sendMail(String toAddr, String title, String content, boolean isHtmlFormat) {
final String username = YiDuConstants.yiduConf.getString(YiDuConfig.MAIL_SMTP_USERNAME);
final String password = YiDuConstants.yiduConf.getString(YiDuConfig.MAIL_SMTP_PASSWORD);
Properties props = new Properties();
props.put("mail.smtp.auth", YiDuConstants.yiduConf.getBoolean(YiDuConfig.MAIL_SMTP_AUTH, true));
props.put("mail.smtp.starttls.enable",
YiDuConstants.yiduConf.getBoolean(YiDuConfig.MAIL_SMTP_STARTTLS_ENABLE, true));
props.put("mail.smtp.host", YiDuConstants.yiduConf.getString(YiDuConfig.MAIL_SMTP_HOST));
props.put("mail.smtp.port", YiDuConstants.yiduConf.getInt(YiDuConfig.MAIL_SMTP_PORT, 25));
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(YiDuConstants.yiduConf.getString(YiDuConfig.MAIL_SMTP_FROM)));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toAddr));
message.setSubject(title);
if (isHtmlFormat) {
message.setContent(content, "text/html");
} else {
message.setText(content);
}
Transport.send(message);
} catch (MessagingException e) {
logger.warn(e);
return false;
}
return true;
}
示例8: sendEmail
import javax.mail.Message; //导入方法依赖的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);
}
示例9: _setupMessage
import javax.mail.Message; //导入方法依赖的package包/类
/**
* Set up a new message.
*/
private Message _setupMessage(Message msg)
{
try
{
String username = _account.getUsername();
String from = username + "@" + _account.getDomain();
List<InternetAddress> to = _getEmailList(getTo());
List<InternetAddress> cc = null;
String ccString = getCc();
if(ccString != null)
{
cc = _getEmailList(ccString);
}
msg.setFrom(new InternetAddress(from));
if ((to != null) && !to.isEmpty())
msg.setRecipients(Message.RecipientType.TO,
to.toArray(new InternetAddress[0]));
if ((cc != null) && !cc.isEmpty())
msg.setRecipients(Message.RecipientType.CC,
cc.toArray(new InternetAddress[0]));
msg.setSubject(_subject == null ? "" : _subject);
if ((_attachment1 == null) &&
(_attachment2 == null) &&
(_attachment3 == null))
{
msg.setText(_content == null ? "" : _content);
}
// Multipart.
else
{
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText(_content == null ? "" : _content);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
if (_attachment1 != null)
_addAttachment(multipart, _attachment1);
if (_attachment2 != null)
_addAttachment(multipart, _attachment2);
if (_attachment3 != null)
_addAttachment(multipart, _attachment3);
// Put all the parts in the message
msg.setContent(multipart);
}
String mailer = "OracleAdfEmailDemo";
msg.setHeader("X-Mailer", mailer);
msg.setSentDate(new Date());
return msg;
}
catch(AddressException ae)
{
_showSendException(ae);
}
catch(MessagingException me)
{
_showSendException(me);
}
catch(Exception e)
{
_showSendException(e);
}
return null;
}
示例10: sendMail
import javax.mail.Message; //导入方法依赖的package包/类
public void sendMail(){
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username,password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
message.setSubject("Website Status Notification.");
message.setText("website is down .");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
System.out.println("Error sending email.");
e.printStackTrace();
}
}
示例11: sendMail
import javax.mail.Message; //导入方法依赖的package包/类
public void sendMail(String uEmail, String URLlink, String Uname, String mailuser, String mailpass, String mailserver, String mailport, String mailsendadd) {
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", mailserver);
props.put("mail.smtp.port", mailport);
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(mailuser, mailpass);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(mailsendadd));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(uEmail));
message.setSubject("Activate your account!!!");
message.setContent("Dear "+Uname+", <BR><BR> Please click the following link to activate your account. <BR><BR> <a href=\""+URLlink+"\">Activate Account</a> <BR><BR> Thank You,", "text/html; charset=utf-8");
Transport.send(message);
System.out.println("Create Account E-mail Sent");
} catch (MessagingException e) {
System.out.println("Error - Create Account E-mail Send FAILED");
throw new RuntimeException(e);
}
}
示例12: send
import javax.mail.Message; //导入方法依赖的package包/类
public void send(String toEmail) {
final String username = "[email protected]";
final String password = "mirapuru1";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(toEmail));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
} finally {
if (session != null) {
//TODO how to close?
}
}
}
示例13: sendUsername
import javax.mail.Message; //导入方法依赖的package包/类
@RequestMapping(value = "sendUsername", method = RequestMethod.POST)
public String sendUsername(@RequestParam("email") String email, Model model, HttpServletResponse response,
HttpServletRequest request) {
if ((usersService.findByEmail(email) == null)) {
model.addAttribute("msg", "Wrong e-mail");
return "loginAndRegistration/reset/forgotUsername";
}
User user = usersService.findByEmail(email);
try {
Session session = EmailActions.authorizeWebShopEmail();
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(ApplicationProperties.SHOP_EMAIL));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email, false));
msg.setSubject("Your login");
msg.setText("Login : " + user.getLogin());
msg.setSentDate(new Date());
Transport.send(msg);
} catch (MessagingException e) {
System.out.println("Error : " + e);
}
model.addAttribute("msg", "Success");
return "loginAndRegistration/reset/forgotUsername";
}
示例14: send
import javax.mail.Message; //导入方法依赖的package包/类
public static void send(String tomail,String msg){
// Recipient's email ID needs to be mentioned.
//String to = "[email protected]";
String to = tomail;
// Sender's email ID needs to be mentioned
String from = "[email protected]";//change accordingly
final String username = "[email protected]";//change accordingly
final String password = "rohanaudia8";//change accordingly
// Assuming you are sending email through relay.jangosmtp.net
String host = "smtp.gmail.com";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", "587");
// Get the Session object.
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
// Create a default MimeMessage object.
Message message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(from));
// Set To: header field of the header.
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
// Set Subject: header field
message.setSubject("Login Credentials");
// Now set the actual message
message.setText("" + msg);
// Send message
Transport.send(message);
System.out.println("Sent message successfully....");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
示例15: doPost
import javax.mail.Message; //导入方法依赖的package包/类
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
// Acquire request parameters we need
String from = request.getParameter("mailfrom");
String to = request.getParameter("mailto");
String subject = request.getParameter("mailsubject");
String content = request.getParameter("mailcontent");
if ((from == null) || (to == null) ||
(subject == null) || (content == null)) {
RequestDispatcher rd =
getServletContext().getRequestDispatcher("/jsp/mail/sendmail.jsp");
rd.forward(request, response);
return;
}
// Prepare the beginning of our response
PrintWriter writer = response.getWriter();
response.setContentType("text/html");
writer.println("<html>");
writer.println("<head>");
writer.println("<title>Example Mail Sending Results</title>");
writer.println("</head>");
writer.println("<body bgcolor=\"white\">");
try {
// Acquire our JavaMail session object
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Session session = (Session) envCtx.lookup("mail/Session");
// Prepare our mail message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress dests[] = new InternetAddress[]
{ new InternetAddress(to) };
message.setRecipients(Message.RecipientType.TO, dests);
message.setSubject(subject);
message.setContent(content, "text/plain");
// Send our mail message
Transport.send(message);
// Report success
writer.println("<strong>Message successfully sent!</strong>");
} catch (Throwable t) {
writer.println("<font color=\"red\">");
writer.print("ENCOUNTERED EXCEPTION: ");
writer.println(HTMLFilter.filter(t.toString()));
writer.println("<pre>");
StringWriter trace = new StringWriter();
t.printStackTrace(new PrintWriter(trace));
writer.print(HTMLFilter.filter(trace.toString()));
writer.println("</pre>");
writer.println("</font>");
}
// Prepare the ending of our response
writer.println("<br><br>");
writer.println("<a href=\"jsp/mail/sendmail.jsp\">Create a new message</a><br>");
writer.println("<a href=\"jsp/index.html\">Back to examples home</a><br>");
writer.println("</body>");
writer.println("</html>");
}