本文整理匯總了Java中javax.mail.internet.MimeMessage.setRecipients方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeMessage.setRecipients方法的具體用法?Java MimeMessage.setRecipients怎麽用?Java MimeMessage.setRecipients使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.mail.internet.MimeMessage
的用法示例。
在下文中一共展示了MimeMessage.setRecipients方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createSimpleMail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* @Method: createSimpleMail
* @Description: ����һ��ֻ�����ı����ݵ��ʼ�
* @param session
* @return
* @throws Exception
*/
public static MimeMessage createSimpleMail(String subject, String content) throws Exception {
//�����ʼ�����
MimeMessage message = new MimeMessage(session);
//ָ���ʼ��ķ�����
message.setFrom(new InternetAddress(username));
if(recipients.contains(";")){
List<InternetAddress> list = new ArrayList<InternetAddress>();
String []median=recipients.split(";");
for(int i=0;i<median.length;i++){
list.add(new InternetAddress(median[i]));
}
InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
message.setRecipients(Message.RecipientType.TO,address);
}else{
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
//�ʼ��ı���
message.setSubject(subject);
//�ʼ����ı�����
message.setContent(content, "text/html;charset=UTF-8");
//���ش����õ��ʼ�����
return message;
}
示例2: sendEmail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
@Override
public void sendEmail(String address, String subject, String content, Map<String, String> headers) throws Exception {
Session session = MailUtilities.makeSession();
if (session == null) {
// LogService.getRoot().warning("Unable to create mail session. Not sending mail to "+address+".");
LogService.getRoot().log(Level.WARNING, "com.rapidminer.tools.MailSenderSMTP.creating_mail_session_error",
address);
}
MimeMessage msg = new MimeMessage(session);
msg.setRecipients(Message.RecipientType.TO, address);
msg.setFrom();
msg.setSubject(subject, "UTF-8");
msg.setSentDate(new Date());
msg.setText(content, "UTF-8");
if (headers != null) {
for (Entry<String, String> header : headers.entrySet()) {
msg.setHeader(header.getKey(), header.getValue());
}
}
Transport.send(msg);
}
示例3: process
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
@Override
public String process() {
logger.info("Running inside MailBatchlet batchlet ");
String fromAddress = stepContext.getProperties().getProperty("mail.from");
String toAddress = stepContext.getProperties().getProperty("mail.to");
try {
MimeMessage m = new MimeMessage(mailSession);
Address from = new InternetAddress(fromAddress);
Address[] to = new InternetAddress[] { new InternetAddress(toAddress) };
m.setFrom(from);
m.setRecipients(TO, to);
m.setSubject("Batch on wildfly executed");
m.setSentDate(new java.util.Date());
m.setContent("Job Execution id " + jobContext.getExecutionId() + " warned disk space getting low!",
"text/plain");
send(m);
} catch (javax.mail.MessagingException e) {
logger.log(SEVERE, "error send mail", e);
}
return COMPLETED.name();
}
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:26,代碼來源:MailBatchlet.java
示例4: sendHtmlEmail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public void sendHtmlEmail(EmailObject email) throws Exception {
// 創建Session實例對象
Session session = Session.getInstance(props, new EmailAuthenticator());
// 創建MimeMessage實例對象
MimeMessage message = new MimeMessage(session);
// 設置郵件主題
message.setSubject(email.getEmailSubject(),"utf-8");
// 設置發送人
message.setFrom(new InternetAddress(from));
// 設置發送時間
message.setSentDate(new Date());
// 設置收件人
message.setRecipients(MimeMessage.RecipientType.TO, InternetAddress.parse(email.getToEmail()));
// 設置html內容為郵件正文,指定MIME類型為text/html類型,並指定字符編碼為gbk
message.setContent(email.getEmailContent(), "text/html;charset=utf-8");
// 保存並生成最終的郵件內容
message.saveChanges();
// 發送郵件
Transport.send(message);
//記錄郵件發送日誌
SendEmailLog sendEmailLog = new SendEmailLog();
sendEmailLog.setToemail(email.getToEmail());
sendEmailLog.setSubject(email.getEmailSubject());
sendEmailLog.setSenddate(new Date());
sendEmailLog.setContent(email.getEmailContent());
sendEmailLogDao.insert(sendEmailLog);
}
示例5: send
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
@Override
public void send(String senderAddress, String senderName, String recipient, String content) {
if (StringUtils.isBlank(senderAddress)) {
throw new FeatureNotAvailable("3PID Email identity: sender address is empty - " +
"You must set a value for notifications to work");
}
if (StringUtils.isBlank(content)) {
throw new InternalServerError("Notification content is empty");
}
try {
InternetAddress sender = new InternetAddress(senderAddress, senderName);
MimeMessage msg = new MimeMessage(session, IOUtils.toInputStream(content, StandardCharsets.UTF_8));
msg.setHeader("X-Mailer", "mxisd"); // FIXME set version
msg.setSentDate(new Date());
msg.setFrom(sender);
msg.setRecipients(Message.RecipientType.TO, recipient);
msg.saveChanges();
log.info("Sending invite to {} via SMTP using {}:{}", recipient, cfg.getHost(), cfg.getPort());
SMTPTransport transport = (SMTPTransport) session.getTransport("smtp");
transport.setStartTLS(cfg.getTls() > 0);
transport.setRequireStartTLS(cfg.getTls() > 1);
log.info("Connecting to {}:{}", cfg.getHost(), cfg.getPort());
transport.connect(cfg.getHost(), cfg.getPort(), cfg.getLogin(), cfg.getPassword());
try {
transport.sendMessage(msg, InternetAddress.parse(recipient));
log.info("Invite to {} was sent", recipient);
} finally {
transport.close();
}
} catch (UnsupportedEncodingException | MessagingException e) {
throw new RuntimeException("Unable to send e-mail invite to " + recipient, e);
}
}
示例6: createMimeMessage
import javax.mail.internet.MimeMessage; //導入方法依賴的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;
}
示例7: send
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* 發送郵件
* @param receiver 接收者郵箱地址
* @param subject 郵件主題
* @param content 郵件內容
*/
public static void send(String receiver, String subject, String content) {
try {
//設置SSL連接、郵件環境
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
Properties props = System.getProperties();
props.setProperty("mail.smtp.host", SMTP_HOST);
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", SMTP_PORT);
props.setProperty("mail.smtp.socketFactory.port", SMTP_SOCKET_FACTORY_PORT);
props.setProperty("mail.smtp.auth", "true");
//建立郵件會話
Session session = Session.getDefaultInstance(props, new Authenticator() {
//身份認證
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(SENDER, PASSWORD);
}
});
//建立郵件對象
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(SENDER, SENDER_NAME));
message.setRecipients(Message.RecipientType.TO, receiver);
message.setSubject(subject);
MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setContent(content, "text/html;charset=UTF-8");
MimeMultipart mimeMultipart = new MimeMultipart();
mimeMultipart.addBodyPart(mimeBodyPart);
message.setContent(mimeMultipart);
message.saveChanges();
Transport.send(message);
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: send
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public void send(String to, String cc, String bcc, String subject,
String content, JavamailConfig javamailConfig)
throws MessagingException {
logger.debug("send : {}, {}", to, subject);
try {
Properties props = createSmtpProperties(javamailConfig);
String username = javamailConfig.getUsername();
String password = javamailConfig.getPassword();
// 創建Session實例對象
Session session = Session.getInstance(props, new SmtpAuthenticator(
username, password));
session.setDebug(false);
// 創建MimeMessage實例對象
MimeMessage message = new MimeMessage(session);
// 設置郵件主題
message.setSubject(subject);
// 設置發送人
message.setFrom(new InternetAddress(username));
// 設置發送時間
message.setSentDate(new Date());
// 設置收件人
message.setRecipients(RecipientType.TO, InternetAddress.parse(to));
// 設置html內容為郵件正文,指定MIME類型為text/html類型,並指定字符編碼為gbk
message.setContent(content, "text/html;charset=gbk");
// 保存並生成最終的郵件內容
message.saveChanges();
// 發送郵件
Transport.send(message);
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
}
示例9: send
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public boolean send() throws Exception {
Properties props = _setProperties();
Session session = Session.getInstance(props, this);
MimeMessage msg = new MimeMessage(session);
msg.setSubject(subject);
msg.setFrom(new InternetAddress("[email protected]"));
msg.setRecipients(MimeMessage.RecipientType.TO, new InternetAddress[] {
new InternetAddress("[email protected]")
});
msg.setSentDate(new Date());
msg.setContent(multipart);
Transport.send(msg);
return true;
}
示例10: createAttachMail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* @Method: createAttachMail
* @Description: ����һ����������ʼ�
* @param session
* @return
* @throws Exception
*/
public static MimeMessage createAttachMail(String subject, String content, String filePath) throws Exception{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
if(recipients.contains(";")){
List<InternetAddress> list = new ArrayList<InternetAddress>();
String []median=recipients.split(";");
for(int i=0;i<median.length;i++){
list.add(new InternetAddress(median[i]));
}
InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
message.setRecipients(Message.RecipientType.TO,address);
}else{
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
message.setSubject(subject);
MimeBodyPart text = new MimeBodyPart();
text.setContent(content, "text/html;charset=UTF-8");
MimeBodyPart attach = new MimeBodyPart();
DataHandler dh = new DataHandler(new FileDataSource(filePath));
attach.setDataHandler(dh);
attach.setFileName(dh.getName());
MimeMultipart mp = new MimeMultipart();
mp.addBodyPart(text);
mp.addBodyPart(attach);
mp.setSubType("mixed");
message.setContent(mp);
message.saveChanges();
return message;
}
示例11: createImageMail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* @Method: createImageMail
* @Description: ����һ���ʼ����Ĵ�ͼƬ���ʼ�
* @param session
* @return
* @throws Exception
*/
public static MimeMessage createImageMail(String subject, String content, String imagePath) throws Exception {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
if(recipients.contains(";")){
List<InternetAddress> list = new ArrayList<InternetAddress>();
String []median=recipients.split(";");
for(int i=0;i<median.length;i++){
list.add(new InternetAddress(median[i]));
}
InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
message.setRecipients(Message.RecipientType.TO,address);
}else{
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
message.setSubject(subject);
MimeBodyPart text = new MimeBodyPart();
text.setContent(content, "text/html;charset=UTF-8");
MimeBodyPart image = new MimeBodyPart();
DataHandler dh = new DataHandler(new FileDataSource(imagePath));
image.setDataHandler(dh);
image.setContentID("xxx.jpg");
MimeMultipart mm = new MimeMultipart();
mm.addBodyPart(text);
mm.addBodyPart(image);
mm.setSubType("related");
message.setContent(mm);
message.saveChanges();
return message;
}
示例12: createMixedMail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* @Method: createMixedMail
* @Description: ����һ��������ʹ�ͼƬ���ʼ�
* @param session
* @return
* @throws Exception
*/
public static MimeMessage createMixedMail(String subject, String content, String imagePath, String filePath) throws Exception {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
if(recipients.contains(";")){
List<InternetAddress> list = new ArrayList<InternetAddress>();
String []median=recipients.split(";");
for(int i=0;i<median.length;i++){
list.add(new InternetAddress(median[i]));
}
InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
message.setRecipients(Message.RecipientType.TO,address);
}else{
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
message.setSubject(subject);
MimeBodyPart text = new MimeBodyPart();
text.setContent(content,"text/html;charset=UTF-8");
MimeBodyPart image = new MimeBodyPart();
image.setDataHandler(new DataHandler(new FileDataSource(imagePath)));
image.setContentID("aaa.jpg");
MimeBodyPart attach = new MimeBodyPart();
DataHandler dh = new DataHandler(new FileDataSource(filePath));
attach.setDataHandler(dh);
attach.setFileName(dh.getName());
MimeMultipart mp = new MimeMultipart();
mp.addBodyPart(text);
mp.addBodyPart(image);
mp.setSubType("related");
MimeBodyPart bodyContent = new MimeBodyPart();
bodyContent.setContent(mp);
message.saveChanges();
return message;
}
示例13: sendEmail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public static void sendEmail(EmailSettingContent emailSetting, String acceptor, String subject, String body) {
Properties props = buildProperty(emailSetting);
Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
String username = null;
String password = null;
if (emailSetting.isAuthenticated()) {
username = emailSetting.getUsername();
password = emailSetting.getPassword();
}
return new PasswordAuthentication(username, password);
}
});
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(emailSetting.getSender()));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(acceptor));
message.setSubject(subject, "utf8");
message.setContent(body, "text/html;charset=utf8");
Transport.send(message);
} catch (Throwable throwable) {
}
}
示例14: buildMailMessage
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private MimeMessage buildMailMessage(Session session, NotificationEvent notifyEvent, String title,
String mailTemplatePath) throws MessagingException {
MimeMessage message = new MimeMessage(session);
// 郵件標題
message.setSubject(title);
String html = IOHelper.readTxtFile(mailTemplatePath, "utf-8");
html = buildMailBody(html, notifyEvent);
// 正文
message.setContent(html, "text/html;charset=utf-8");
// 發件人
message.setFrom(username);
String addressStr = notifyEvent.getArg(cName);
String[] toAddr = addressStr.split(",");
Address[] receiver = new Address[toAddr.length];
int i = 0;
for (String addr : toAddr) {
if (!StringHelper.isEmpty(addr)) {
receiver[i] = new InternetAddress(addr);
i++;
}
}
// 收件人
message.setRecipients(MimeMessage.RecipientType.TO, receiver);
message.saveChanges();
return message;
}
示例15: sendMail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public void sendMail(String account) throws Exception {
message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(account, false));
message.setSubject("DO NOT REPLY");
message.setDataHandler(new DataHandler(new ByteArrayDataSource(getMailContent(), "text/html")));
message.setSentDate(new Date());
transport = session.getTransport();
transport.connect("smtp-mail.outlook.com", "[email protected]", "BaoZJ960606");
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}