精华内容
下载资源
问答
  • java发送html邮件

    千次阅读 2018-03-29 11:43:42
    见下面java代码 @Override public String attach(String from, String[] to, String[] cc, String subject, String content, String path, String name) throws Exception { HtmlEmail email = n...

    见下面java代码

    @Override
       public String attach(String from, String[] to, String[] cc, String subject, String content,
                String path, String name) throws Exception {
            HtmlEmail email = new HtmlEmail();
            EmailAttachment attachment = new EmailAttachment();
            attachment.setPath(path); // 邮件附件路径
            attachment.setName(name);// 邮件发送出去时附件名
            email.attach(attachment);
            email.setHostName("");  // 主机名
            email.setFrom(from); // 发送时发件人名称
            if (to != null) {
                for (String email2 : to) {
                    if (email2 != null && email2.trim().length() > 0) {
                        email.addTo(email2.trim());
                    }
                }
            }
            if (cc != null) {
                for (String email2 : cc) {
                    if (email2 != null && email2.trim().length() > 0) {
                        email.addCc(email2.trim());
                    }
                }
            }
            email.setCharset("UTF-8");
            email.setSubject(subject);// 邮件主题
            email.setAuthentication("用户名","密码");
            email.setHtmlMsg(content);//邮件内容
            String status = email.send();
            logger.info("================EmailDSImpl  send result:" + status);
            return status;
        }
    
    

    关于内容中带图片的,个人建议最好使用图片的base64,以字符串形式放入conten中。

    展开全文
  • Java发送html标签内容的邮件实例代码发布于 2020-6-18|复制链接下面小妖就为大家带来一篇Java发送html标签内容的邮件实例代码。小妖觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小妖过来看看吧...

    Java发送带html标签内容的邮件实例代码

    发布于 2020-6-18|

    复制链接

    下面小妖就为大家带来一篇Java发送带html标签内容的邮件实例代码。小妖觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小妖过来看看吧

    如下所示:

    ```java

    package test;

    import javax.mail.internet.InternetAddress;

    import javax.mail.internet.MimeMessage;

    import javax.mail.internet.MimeUtility;

    import javax.mail.Session;

    import javax.mail.MessagingException;

    import javax.mail.Transport;

    public class SendHtmlMail {

    public static void sendMessage(String smtpHost, String from, String to,String subject, String messageText) throws MessagingException,

    java.io.UnsupportedEncodingException {

    // Step 1: Configure the mail session

    System.out.println("Configuring mail session for: " + smtpHost);

    java.util.Properties props = new java.util.Properties();

    props.setProperty("mail.smtp.auth", "true");// 指定是否需要SMTP验证

    props.setProperty("mail.smtp.host", smtpHost);// 指定SMTP服务器

    props.put("mail.transport.protocol", "smtp");

    Session mailSession = Session.getDefaultInstance(props);

    mailSession.setDebug(false);// 是否在控制台显示debug信息

    // Step 2: Construct the message

    System.out.println("Constructing message - from=" + from + " to=" + to);

    InternetAddress fromAddress = new InternetAddress(from);

    InternetAddress toAddress = new InternetAddress(to);

    MimeMessage testMessage = new MimeMessage(mailSession);

    testMessage.setFrom(fromAddress);

    testMessage.addRecipient(javax.mail.Message.RecipientType.TO, toAddress);

    testMessage.setSentDate(new java.util.Date());

    testMessage.setSubject(MimeUtility.encodeText(subject, "gb2312", "B"));

    testMessage.setContent(messageText, "text/html;charset=gb2312");

    System.out.println("Message constructed");

    // Step 3: Now send the message

    Transport transport = mailSession.getTransport("smtp");

    transport.connect(smtpHost, "riteng_mes", "ri-teng1234");

    transport.sendMessage(testMessage, testMessage.getAllRecipients());

    transport.close();

    System.out.println("Message sent!");

    }

    public static void main(String[] args) {

    String smtpHost = "10.131.119.36";

    String from = "Riteng_Mes@casetekcorp.com";

    String to = "Qiang1_Zhang@intra.casetekcorp.com";

    String subject = "html邮件测试"; // subject javamail自动转码

    StringBuffer theMessage = new StringBuffer();

    theMessage.append("这倒霉孩子");

    theMessage.append("");

    theMessage.append("年年失望年年望");

    theMessage.append("aaabbbcccddd");

    try {

    SendHtmlMail.sendMessage(smtpHost, from, to, subject,theMessage.toString());

    } catch (javax.mail.MessagingException exc) {

    exc.printStackTrace();

    } catch (java.io.UnsupportedEncodingException exc) {

    exc.printStackTrace();

    }

    }

    }

    ```

    展开全文
  • 序本文展示一下如何使用spring mail来发送html邮件。mavenorg.springframework.bootspring-boot-starter-mail发送图片public void send(String from, String[] toMails, String subject, String text,Map inlines) ...

    本文展示一下如何使用spring mail来发送html邮件。

    maven

    org.springframework.boot

    spring-boot-starter-mail

    发送图片

    public void send(String from, String[] toMails, String subject, String text,

    Map inlines) throws Exception{

    MimeMessage mimeMessage = mailSender.createMimeMessage();

    MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);

    helper.setFrom(from);

    helper.setTo(toMails);

    helper.setSubject(subject);

    helper.setText(text, true); //支持html

    // 增加inline

    if(inlines != null){

    for(Map.Entry entry: inlines.entrySet()){

    if(entry.getValue() instanceof ClassPathResource){

    helper.addInline(entry.getKey(), (Resource) entry.getValue());

    }

    }

    }

    mailSender.send(mimeMessage);

    }

    测试

    发送实例

    ClassPathResource classPathResource = new ClassPathResource("image_2.png");

    Map att = new HashMap<>();

    att.put("image",classPathResource);

    String content = "

    spring mail发送实例

    ";

    try{

    mailService.send(new String[]{"xxxxx@163.com"},"spring mail发送实例",content,att);

    }catch (Exception e){

    e.printStackTrace();

    }

    异常

    org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 554 DT:SPM 126 smtp7,DsmowAB3U6X1_LdZjIz+Aw--.26008S3 1505230070,please see http://mail.163.com/help/help_spam_16.htm?ip=123.65.107.103&hostid=smtp7&time=1505230070

    ; message exception details (1) are:

    Failed message 1:

    com.sun.mail.smtp.SMTPSendFailedException: 554 DT:SPM 126 smtp7,DsmowAB3U6X1_LdZjIz+Aw--.26008S3 1505230070,please see http://mail.163.com/help/help_spam_16.htm?ip=123.65.107.103&hostid=smtp7&time=1505230070

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2267)

    at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:2045)

    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1260)

    at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:448)

    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345)

    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340)

    错误码554

    554 DT:SPM 发送的邮件内容包含了未被许可的信息,或被系统识别为垃圾邮件。请检查是否有用户发送病毒或者垃圾邮件;

    被网易邮箱识别为垃圾邮件了,有个歪招,就是把发送邮箱添加到cc里头

    helper.setCc(from);

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

    展开全文
  • String subject = "html邮件测试"; // subject javamail自动转码 StringBuffer theMessage = new StringBuffer(); theMessage.append(" 这倒霉孩子"); theMessage.append(" "); theMessage.append("年年失望年年望...

    package test;

    import javax.mail.internet.InternetAddress;

    import javax.mail.internet.MimeMessage;

    import javax.mail.internet.MimeUtility;

    import javax.mail.Session;

    import javax.mail.MessagingException;

    import javax.mail.Transport;

    public class SendHtmlMail {

    public static void sendMessage(String smtpHost, String from, String to,String subject, String messageText) throws MessagingException,

    java.io.UnsupportedEncodingException {

    // Step 1: Configure the mail session

    System.out.println("Configuring mail session for: " + smtpHost);

    java.util.Properties props = new java.util.Properties();

    props.setProperty("mail.smtp.auth", "true");// 指定是否需要SMTP验证

    props.setProperty("mail.smtp.host", smtpHost);// 指定SMTP服务器

    props.put("mail.transport.protocol", "smtp");

    Session mailSession = Session.getDefaultInstance(props);

    mailSession.setDebug(false);// 是否在控制台显示debug信息

    // Step 2: Construct the message

    System.out.println("Constructing message - from=" + from + " to=" + to);

    InternetAddress fromAddress = new InternetAddress(from);

    InternetAddress toAddress = new InternetAddress(to);

    MimeMessage testMessage = new MimeMessage(mailSession);

    testMessage.setFrom(fromAddress);

    testMessage.addRecipient(javax.mail.Message.RecipientType.TO, toAddress);

    testMessage.setSentDate(new java.util.Date());

    testMessage.setSubject(MimeUtility.encodeText(subject, "gb2312", "B"));

    testMessage.setContent(messageText, "text/html;charset=gb2312");

    System.out.println("Message constructed");

    // Step 3: Now send the message

    Transport transport = mailSession.getTransport("smtp");

    transport.connect(smtpHost, "riteng_mes", "ri-teng1234");

    transport.sendMessage(testMessage, testMessage.getAllRecipients());

    transport.close();

    System.out.println("Message sent!");

    }

    public static void main(String[] args) {

    String smtpHost = "10.131.119.36";

    String from = "Riteng_Mes@casetekcorp.com";

    String to = "Qiang1_Zhang@intra.casetekcorp.com";

    String subject = "html邮件测试"; // subject javamail自动转码

    StringBuffer theMessage = new StringBuffer();

    theMessage.append("

    这倒霉孩子

    ");

    theMessage.append("


    ");

    theMessage.append("年年失望年年望");

    theMessage.append("

    aaabbb
    cccddd
    ");

    try {

    SendHtmlMail.sendMessage(smtpHost, from, to, subject,theMessage.toString());

    } catch (javax.mail.MessagingException exc) {

    exc.printStackTrace();

    } catch (java.io.UnsupportedEncodingException exc) {

    exc.printStackTrace();

    }

    }

    }

    展开全文
  • 使用javamail发送html邮件比较复杂1packageorg.tatan.mail;23importjavax.mail.internet.InternetAddress;4importjavax.mail.internet.MimeMessage;5importjavax.mail.internet.MimeUtility;6importjavax.mail....
  • applicationContext文件配置内容如下:true剩下的,我就直接捞干的.../*** 邮件对象* @author liuhuan* Created by Administrator on 2014/10/24.*/public class EmailVo{/*** 邮件发送者*/private String sender;/*...
  • String subject = "html邮件附件测试"; //subject javamail自动转码 StringBuffer theMessage = new StringBuffer(); theMessage.append(" 这倒霉孩子"); theMessage.append(" "); theMessage.append("年年失望年年...
  • 需要把网页标签中的双引号替换为 " 或者 \\\"   例如 ;margin: 0 auto\\\">   or    ;container" style="...转载于:https://www.cnblogs.com/binz/p/8360522.html
  • 我正在尝试使用JavaMail以html格式发送电子邮件,但它似乎始终只在Outlook中显示为文本电子邮件。这是我的代码:try{Properties props = System.getProperties();props.put("mail.smtp.host", mailserver);props.put...
  • 展开全部1、如果是想用HTML做发送的内容及布局的话,那就不要用js2、如果在发送邮件的时候将636f707962616964757a686964616f31333339663336HTML文件作为附件的话,那是可以有js的Java发送邮件需要用到JavaMail,先到...
  • java发送email邮件.

    2017-02-20 18:15:46
    demo介绍:http://blog.csdn.net/love_xiolan/article/details/56016576 java发送email邮件 1.发送普通email邮件 2.发送带附件的email邮件 3.邮件抄送和密送 4.发送html邮件 5.发送模板文件
  • java 发送HTML格式邮件

    2011-07-22 10:34:18
    java mail 发送html格式的邮件
  • } /** * @param sendMail * @param orderNo * @param sendJson * @return void * @Description:发送邮件 * @Author:SimonHu * @Date: 2020/11/5 10:25 */ public void sendSimpleMail(String sendMail, String ...
  • .index1.jsp发送文本型文件SMTP服务器:登录账号:登录密码:发件人邮箱:收件人邮箱:邮件主题:邮件内容:2.SendHtmlMail.javapackage com.lhb.mail;import java.util.Date;import java.util.Properties;import ...
  • 使用java发送邮件的时候,需要先下载两个jar包,连接如下:然后将这连个包导入,博主用的是IDEA,导包的教程连接:https://www.cnblogs.com/yulia/p/6824058.html由于QQ邮箱需要SSL加密,这个需要在自己的QQ邮箱中...
  • java发送HTML模版邮件

    热门讨论 2014-01-22 14:30:20
    java实现的根据html模版内容发送邮件,这是一个完整的eclipse项目,包含jar包,导入即可运行
  • importjava.io.ByteArrayOutputStream;importjava.io.FileInputStream;importjava.io.IOException;importjava.util.Arrays;importjava.util.Date;importjava.util.Properties;importjavax.activation...
  • /*** 发送邮件 可以带有HTML格式*@paramtoUser*@paramrecipients*@paramcontent*@paramsubject*@throwsException*/public static void noticePushCommandForHtml(String toUser, List ccList, String content, ...
  • 发送文本型文件SMTP服务器:登录账号:登录密码:发件人邮箱:收件人邮箱:邮件主题:邮件内容:2.SendHtmlMail.javapackage com.lhb.mail;import java.util.Date;import java.util.Properties;import javax.mail....
  • 常见的报警提醒有发送短信和发送邮件,由于发送短信需要对接第三方api且需要付费,这篇文章将介绍如何使用java实现发送邮件,包括发送普通文本邮件、普通html格式的邮件、配置模板的html格式邮件。技术说明Jdk8...
  • Java发送电子邮件

    2018-12-03 18:46:59
    Java 发送邮件 使用Java应用程序发送E-mail十分简单,但是首先你应该在你的机器上安装JavaMail API 和Java Activation Framework (JAF) 。 你可以在 JavaMail ...
  • String subject = "html邮件测试"; //subject javamail自动转码 StringBuffer theMessage = new StringBuffer(); theMessage.append(" 这倒霉孩子"); theMessage.append(" "); theMessage.append("年年失望年年望")...
  • java发送邮件

    2012-07-06 11:59:02
    java发送邮件的封装,支持HTML格式和TEXT格式的邮件内容
  • Java发送邮件,优美html邮件模板分享

    千次阅读 2019-09-24 12:47:27
    以前有用JavaMail写过发送html邮件,当时在benchmark网站自己设计了个html模板,分享记录一下。 预览: ...Java实现发送html邮件可参考博客SpringBoot使用JavaMailSender实现发送邮件功能,...
  • Java发送邮件

    2019-09-30 16:08:49
    Java发送邮件初窥 一、背景  最近朋友的公司有用到这个功能,之前对这一块也不是很熟悉,就和他一起解决出现的异常的同时,也初窥一下使用Apache Common Email组件进行邮件发送。 二、Java发送邮件的注意...
  • importjava.io.File;importjava.net.URL;importorg.apache.commons.mail.Email;importorg.apache.commons.mail.EmailAttachment;importorg.apache.commons.mail.EmailException;importorg.apache.commons.mail....

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,363
精华内容 545
关键字:

java发送html邮件

java 订阅