`
learnmore
  • 浏览: 588934 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

common email发送邮件

    博客分类:
  • java
 
阅读更多
项目地址:http://commons.apache.org/email/userguide.html
1.简单邮件发送
  Email email = new SimpleEmail();
email.setHostName("smtp.gmail.com");
email.setSmtpPort(587);
email.setAuthenticator(new DefaultAuthenticator("username", "password"));
email.setTLS(true);
email.setFrom("user@gmail.com");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("foo@bar.com");
email.send();


2.带附件的邮件发送
import org.apache.commons.mail.*;
...

  // Create the attachment
  EmailAttachment attachment = new EmailAttachment();
  attachment.setPath("mypictures/john.jpg");
  attachment.setDisposition(EmailAttachment.ATTACHMENT);
  attachment.setDescription("Picture of John");
  attachment.setName("John");

  // Create the email message
  MultiPartEmail email = new MultiPartEmail();
  email.setHostName("mail.myserver.com");
  email.addTo("jdoe@somewhere.org", "John Doe");
  email.setAuthentication("me@apache.org", "password");
  email.setFrom("me@apache.org", "Me");
  email.setSubject("The picture");
  email.setMsg("Here is the picture you wanted");

  // add the attachment
  email.attach(attachment);

  // send the email
  email.send();


3.利用url自动下载并发送邮件
 import org.apache.commons.mail.*;
...

  // Create the attachment
  EmailAttachment attachment = new EmailAttachment();
  attachment.setURL(new URL("http://www.apache.org/images/asf_logo_wide.gif"));
  attachment.setDisposition(EmailAttachment.ATTACHMENT);
  attachment.setDescription("Apache logo");
  attachment.setName("Apache logo");

  // Create the email message
  MultiPartEmail email = new MultiPartEmail();
  email.setHostName("mail.myserver.com");
  email.setAuthentication("me@apache.org", "password");
  email.addTo("jdoe@somewhere.org", "John Doe");
  email.setFrom("me@apache.org", "Me");
  email.setSubject("The logo");
  email.setMsg("Here is Apache's logo");
  
  // add the attachment
  email.attach(attachment);

  // send the email
  email.send();


4.发送html格式的邮件
  import org.apache.commons.mail.HtmlEmail;
...

  // Create the email message
  HtmlEmail email = new HtmlEmail();
  email.setHostName("mail.myserver.com");
  email.setAuthentication("me@apache.org", "password");
  email.addTo("jdoe@somewhere.org", "John Doe");
  email.setFrom("me@apache.org", "Me");
  email.setSubject("Test email with inline image");
  
  // embed the image and get the content id
  URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
  String cid = email.embed(url, "Apache logo");
  
  // set the html message
  email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"+cid+"\"></html>");

  // set the alternative message
  email.setTextMsg("Your email client does not support HTML messages");

  // send the email
  email.send();


5.批量发送内嵌图片的邮件
  import org.apache.commons.mail.HtmlEmail;
...

  // load your HTML email template
  String htmlEmailTemplate = ....
  
  // Create the email message
  HtmlEmail email = new ImageHtmlEmail();
  email.setHostName("mail.myserver.com");
  email.setAuthentication("me@apache.org", "password");
  email.addTo("jdoe@somewhere.org", "John Doe");
  email.setFrom("me@apache.org", "Me");
  email.setSubject("Test email with inline image");
  
  // embed the image and get the content id
  URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
  String cid = email.embed(url, "Apache logo");
  
  // set the html message
  email.setHtmlMsg(htmlEmailTemplate, new File("").toURI().toURL(), false);

  // set the alternative message
  email.setTextMsg("Your email client does not support HTML messages");

  // send the email
  email.send();

分享到:
评论

相关推荐

    commons email 发送html邮件完整优化实例

    commons email 发送html邮件完整优化实例

    thinkphp onethink 通用发送邮件源码 phpmailer插件

    function.php是公共函数库 位置一般在application/common/common/...在任何想发送邮件的地方,比如注册控制器中,send_mail(邮件地址,主题,邮件内容); 这样就行了,超简单 比如 send_mail($email,$subject,$body);

    免安装Mail插件发送邮件类MailHelper

    Common.MailDetail md = new Common.MailDetail();... md.Title = "邮件提醒-"; md.Recipients.Add(email); md.UserName = MailServerUserName; if (Common.MailHelper.SendMail(md)) { } #endregion

    cl-ses:使用AWS SES从Common Lisp发送电子邮件

    cl-ses是Common Lisp软件包,用于通过AWS的SES发送电子邮件。 用法 cl-ses导出send-email功能: (cl-ses:send-email :from " me@example.com " :to " you@example.com " :subject " Hello from CL-SES " :...

    smtp 发送邮件给多个用户,带附件

    smtp 发送邮件给多个用户,带附件,测试本机smtp服务是否正常.附带 excel导出报表,在发送邮件

    Platinum Email Sender:以最聪明的方式简单的电子邮件发件人应用程序。-开源

    Platinum Email Sender是基于.net的WINDOWS平台相关的电子邮件发件人。 它可以让您以最快的方式发送电子邮件。 SMTP服务器名称和电子邮件将自动从“发件人”字段中获取。 如果选中“记住您的登录名”,它将保存您的...

    解决azkaban使用腾讯企业邮箱发邮件失败问题

    解决azkaban使用腾讯企业邮箱发邮件失败问题 azkaban-common/src/main/java/azkaban/utils/EmailMessage.java中 在sendEmail()方法里props的配置代码下加入以下几行代码: import java.security.Security; Security...

    java发HTML 邮件类和包

    java发HTML 邮件类和包 package com.common.util.mail; public String Test(String str) { String htmlMessage = "&lt;html&gt;&lt;body&gt;&lt;font size='15' color='red'&gt;This is a test mail.&lt;/font&gt;&lt;/body&gt...

    PHPMailer ThinkPHP实现自动发送邮件功能

    2.然后在项目目录下common文件夹下,在common.PHP(ThinkPHP中此文件会自动被引用,如果没有,新建一个common.php)中新增调用发送邮件的函数: /********************************Email**************************...

    PHPMailer (本人用的tp5 将其放置extend/org 文件下)

    namespace app\common\server\email; use org\PHPMailer\src\PHPMailer; class EmailServer extends \app\common\server\BaseServer { /* * 发送邮箱验证码 */ public function send($email) { if (!is_email...

    thinkphpEmail:thinkphp+PHPMailer发邮件

    thinkphpEmail##thinkphp+PHPMailer发邮件###使用方法1.添加PHPMailer文件夹到Thinkphp/Library/Vendor,PHPMailer这里我只留了三个文件;2.调用Application/Common/function.php的sendEmail函数/**author:10xjzheng...

    azkaban-common-0.1.0-SNAPSHOT.jar

    解决azkaban使用腾讯企业邮箱发邮件失败问题,因为腾讯的企业邮箱是用smtps协议,也就是ssl , 端口是465,增加相关代码,并打包,经测试可以直接使用。 我的azkaban的版本是“3.84.10”。

    通用代理服务器 Common Proxy Server ParisPorxy

    软件中绝对不含任何形式的后门和trojan程序,如果您发现任何木马迹象,请发邮件和我联系 软件使用说明: 请大家自己测试,软件支持命令行输入,也可以安装成服务,如果安装成服务,服务器端口可以走通本软件的...

    ssl-cert-check:SSL证书即将到期时发送通知

    该脚本旨在从cron运行,并且可以通过nagios发送电子邮件警告或记录警报。 用法: $ ./ssl-cert-check Usage: ./ssl-cert-check [ -e email address ] [ -E sender email address ] [ -x days ] [-q] [-a] [-b] [-h...

    sendEmail

    sendEmail项目结构发送电子邮件附件生成Excel文件存放路径common封装公用功能目录config执行配置存放文件fileDir存放各种路径变量模型数据库模型my_email封装的发送邮件方法sql SQL相关文档存放路径config SQL配置...

    高清监控系统兼容所有网络摄像机

    Email fail, please check your parameter=发送测试邮件失败,请检查您的参数设置 Email Result=邮件测试结果 Seconds=秒 ;存储 None=未找到存储设备 Unformatted=未格式化 Storeage is full=存储设备已满 ...

    基于SpringBoot+ORM-Mybatis+SpringMVC和多种组件构建的企业信息化开发基础平台源码+项目说明.zip

    使用JavaEmail插件实现邮件发送,记得需要开启SSl验证 ![Image text](https://gitee.com/362330721/jeeplatform/raw/master/screenshot/发送邮件.png) ### OA管理系统(待开发) 接入CAS Server实现单点登录 ### CMS...

    PHP基础教程 是一个比较有价值的PHP新手教程!

    但是PHP的邮件列表很是有用而且除非你正在运行像Yahoo!或者Amazon.com这样的极受欢迎的站点,你不会感觉出PHP的速度与其他的有什么不同。最起码我就没有感觉出来!好了,让我们来看看PHP有那些优点: - 学习过程 ...

    ZendFramework中文文档

    9.4.3. Basic Zend_Date Operations Common to Many Date Parts 9.4.3.1. List of Date Parts 9.4.3.2. List of Date Operations 9.4.4. Comparing Dates 9.4.5. Getting Dates and Date Parts 9.4.6. Working ...

    jfinalpluginsjfinal-dreampie.zip

    9.mailer 邮件发送plugin,使用akka异步发送邮件  Akka.system&#40;&#41;.scheduler().scheduleOnce(Duration.create(1000, TimeUnit.MILLISECONDS),  new Runnable() {  @Override  public void run() ...

Global site tag (gtag.js) - Google Analytics