本文整理汇总了Java中javax.mail.internet.MimeMessage.saveChanges方法的典型用法代码示例。如果您正苦于以下问题:Java MimeMessage.saveChanges方法的具体用法?Java MimeMessage.saveChanges怎么用?Java MimeMessage.saveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.internet.MimeMessage
的用法示例。
在下文中一共展示了MimeMessage.saveChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: buildEmailMessage
import javax.mail.internet.MimeMessage; //导入方法依赖的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;
}
示例4: 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);
}
}
示例5: createMimeMessage
import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
* 创建一封只包含文本的简单邮件
*
* @param session
* 和服务器交互的会话
* @param sendMail
* 发件人邮箱
* @param receiveMail
* 收件人邮箱
* @return
* @throws Exception
*/
public static MimeMessage createMimeMessage(Session session, String sendMail, String receiveMail, String username,String pwd)
throws Exception {
// 1. 创建一封邮件
MimeMessage message = new MimeMessage(session);
// 2. From: 发件人(昵称有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改昵称)
message.setFrom(new InternetAddress(sendMail, "Mircle", "UTF-8"));
// 3. To: 收件人(可以增加多个收件人、抄送、密送)
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "", "UTF-8"));
// 4. Subject: 邮件主题(标题有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改标题)
message.setSubject(subject, "UTF-8");
// 5. Content: 邮件正文(可以使用html标签)(内容有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改发送内容)
message.setContent(getContent(username,pwd), "text/html;charset=UTF-8");
// 6. 设置发件时间
message.setSentDate(new Date());
// 7. 保存设置
message.saveChanges();
return message;
}
示例6: sendAccountActivateEmail
import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
public static void sendAccountActivateEmail(String email, String uuid, int userId) {
Session session;
try {
session = getSession();
MimeMessage message = new MimeMessage(session);
message.setSubject("������֤��");
message.setSentDate(new Date());
message.setFrom(new InternetAddress(FROM));
message.setRecipient(RecipientType.TO, new InternetAddress(email));
message.setContent("�����û�"+userId+":������֤��Ϊ��"+uuid,
"text/html;charset=utf-8");
message.saveChanges();
Transport.send(message);
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: createFeedBackMsg
import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
/**
* 创建一封反馈邮件
* @param session
* @param sendMail
* @param detail
* @return
*/
private MimeMessage createFeedBackMsg(Session session, String sendMail, String detail) throws UnsupportedEncodingException, MessagingException {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(sendMail, "吃在华科", "UTF-8"));
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress("[email protected]", this.name, "UTF-8"));
message.setSubject("吃在华科用户反馈", "UTF-8");
String content = UserStatus.getUserStatus().getName()+"\n"+detail;
message.setContent(content, "text/html;charset=UTF-8");
message.setSentDate(new Date());
message.saveChanges();
return message;
}
示例8: 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();
}
}
示例9: 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);
}
}
示例10: 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();
}
}
示例11: 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();
}
}
示例12: 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;
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}