当前位置: 首页 > news >正文

青州建网站青岛营销型网站推广

青州建网站,青岛营销型网站推广,精品课程 网站建设质量,个人年终总结ppt模板下载抽象 本博客的目的是演示如何使用Java Mail通过具有TLS连接的SMTP服务器发送电子邮件。 免责声明 这篇文章仅供参考。 在使用所提供的任何信息之前#xff0c;请认真思考。 从中学到东西#xff0c;但最终自己做出决定#xff0c;风险自负。 要求 我使用以下主要技术完成了… 抽象 本博客的目的是演示如何使用Java Mail通过具有TLS连接的SMTP服务器发送电子邮件。 免责声明 这篇文章仅供参考。 在使用所提供的任何信息之前请认真思考。 从中学到东西但最终自己做出决定风险自负。 要求 我使用以下主要技术完成了本文的所有工作。 您可能可以使用不同的技术或版本来做相同的事情但不能保证。 NetBeans 11.2 Maven 3.3.9与NetBeans捆绑在一起 Java 11zulu11.35.15-ca-jdk11.0.5-win_x64 dependency groupIdjavax.mail/groupId artifactIdmail/artifactId version 1.4 /version scopetest/scope /dependency 下载 访问我的GitHub页面https://github.com/mjremijan以查看我所有的开源项目。 这篇文章的代码位于thoth-email-via-tls模块中的https://github.com/mjremijan/thoth-email 。 物产 本示例使用smtp-tls-outlook.properties文件保存SMTP服务器信息。 我用我个人的Outlook帐户进行测试因此使用这个词的outlook属性文件中的名称。 重要的是文件的内容如清单1所示。 清单1 –属性文件 # This is the name of the SMTP host machine. host # This is the port number of the SMTP host machine. # The same host may support both SSL and TLS but on # different ports. So make sure you get the TLS port. port # This is what you use in the “username” field when # you login. Typically # you login. Typically this is the same as your email # address, but this isnt always the case . username # This is what you use in the “password” field when # you login. This value is CLEAR TEXT, so keep # you login. This value is CLEAR TEXT, so keep this # properties file safe. password # This is the email address you want for the # emails FROM field. Enter the value using # the format shown below. Typically # the format shown below. Typically this is # just your email address for the account. fromFIRSTNAME LASTNAME ADDRESS EMAIL .COM # This is the email address you want for the # emails REPLY_TO field. Enter the value using # the format shown below. Typically # the format shown below. Typically this is # just your email address for the account. Also the account. Also # typically this is the same as from above. # But be warned, if an emails FROM and REPLY_TO # are different, thats may be flagged as spam # and never be delivered. So keep from and # reply the same for initial testing replyFIRSTNAME LASTNAME ADDRESS EMAIL .COM # This is the email address you want to send # the email to. For testing, its a good idea # to send it to yourself first. toFIRSTNAME LASTNAME ADDRESS EMAIL .COM 现在您有了属性文件接下来让我们看一下代码。 码 这是一个JUnit测试演示了如何使用Java Mail通过具有TLS连接的SMTP服务器发送电子邮件。 清单2显示了代码。 注意对于初始测试请始终检查您的SPAM文件夹。 可以始终添加一条规则以将其传送到您的INBOX。 清单2 – Java Mail示例 package org.thoth.email.via.tls; import java.net.InetAddress; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Properties; import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class TlsTest { public TlsTest() { } String now, hostname; protected String now, hostname; protected Properties outlook; BeforeEach public void setUp() throws Exception { now new SimpleDateFormat( MM-dd-yyyy hh:mm:ss a ).format( new Date()); hostname InetAddress.getLocalHost().getHostName(); outlook new Properties(); outlook.load( this .getClass().getResourceAsStream( /smtp-tls-outlook.properties )); } Test public void a_test() throws Exception { // Create MimeMultipart MimeMultipart content new MimeMultipart( related ); // html part { MimeBodyPart textPart new MimeBodyPart(); textPart.setText( htmlbody pTime: now /p pFrom: hostname /p /body/html , UTF8 , html ); content.addBodyPart(textPart); } // properties Properties props new Properties(); { props.setProperty( mail.smtp.auth , true ); props.setProperty( mail.smtp.host , outlook.getProperty( host )); props.setProperty( mail.smtp.port , outlook.getProperty( port )); props.setProperty( mail.smtp.starttls.enable , true ); } Session smtp null ; { smtp Session.getInstance(props, new Authenticator() { Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( outlook.getProperty( username ) , outlook.getProperty( password ) ); } }); smtp.setDebug( true ); smtp.setDebugOut(System.out); } MimeMessage m new MimeMessage(smtp); { m.setRecipient(Message.RecipientType.TO, new InternetAddress(outlook.getProperty( to ))); m.setSubject( thoth-email TLS test now); InternetAddress from null ; { from new InternetAddress(outlook.getProperty( from )); from.setPersonal( Thoth Email ); m.setFrom(from); } InternetAddress reply null ; { reply new InternetAddress(outlook.getProperty( reply )); m.setReplyTo( new InternetAddress[] {reply}); } m.setContent(content); } Transport.send(m); } } 摘要 发送邮件的代码不是很困难。 成功接收电子邮件而不将其标记为垃圾邮件是另一回事。 但是如果您遵循此示例请使用有效的帐户并且不要过度使用它则应该可以。 该博客显示了如何使用Java Mail通过具有TLS连接的SMTP服务器发送电子邮件。 翻译自: https://www.javacodegeeks.com/2020/02/java-mail-sent-over-tls.html
http://www.sadfv.cn/news/194057/

相关文章:

  • wordpress 建视频网站石家庄建设银行网点
  • 做塑胶网站需要什么房地产网站模板 下载
  • 建网站设计虚拟主机空间发布网站
  • 电商网站需要多少钱幻想次元wordpress
  • 张家界建设信息网站百度云建网站
  • 官方网站建设哪家公司好深圳网站定制价格低
  • 阿里网站导航怎么做的网站设计咨询网站
  • 常州网站外包wordpress速度快
  • 医院做网站备案需要哪些资料如何逐步提升网站权重
  • 音乐网站建设程序建站哪家好联系兴田德润
  • 资源下载站 wordpress动漫设计与游戏制作学什么
  • 高端网站设计欣赏个体工商户经营范围做网站
  • 做网站推荐源创网络个人做网站需要备案吗
  • 网站怎么做才有效果网站开发用什么浏览器
  • 哪里去找做的好看的网站深圳菜谱制作
  • 视频网站是怎么做权限管理的WordPress中文音乐主题
  • 农业推广网站建设应用商店下载app
  • 兰州工程建设信息网站景德镇建设企业网站
  • 深圳福田区住房和建设局网站产品开发岗位职责
  • 珠海网站建设的公司排名中国建设注册管理中心网站
  • 义乌做网站公司哈密seo
  • wordpress建站模板电商网站用php做的吗
  • 启东市住房城乡建设局网站福州建设公司名单
  • 公司建站文案给网站公司看的卸载ghost版wordpress
  • 新开传奇网站180火龙网站建设合同印花税
  • 深圳营销型网站策划北京网站建设华网
  • 传奇网站架设方法免费建站网站网页
  • 建网站有哪些费用汕头企业网络推广
  • 苏州企业网站建设公司只选亿企邦wordpress 本地链接
  • 有限公司网站建设 互成网络地址 四川企业查询网