简体   繁体   English

使用Java发送电子邮件

[英]Sending Email using Java

I want my Java application to send out emails to users. 我希望我的Java应用程序向用户发送电子邮件。 But I cant get a good solution. 但是我找不到一个好的解决方案。

Now, I got some on Google but they use a SMTP server which I dont have. 现在,我在Google上找到了一些,但它们使用的是我没有的SMTP服务器。 I was wondering if setting up one on my Linux machine would be easy? 我想知道在我的Linux机器上设置一个是否容易?

So, I am using mailx now to send out emails but it sends emails from root which is definately not good. 因此,我现在正在使用mailx发送电子邮件,但是它从根目录发送电子邮件肯定不是很好。 Is there any way to send out emails from a proper email using java? 有没有办法使用Java从适当的电子邮件中发送电子邮件? like you can do in php and other languages? 像你可以用PHP和其他语言吗?

Use commons-email to send email from java in a simple, straightforward way (see the docs). 使用commons-email以简单,直接的方式从Java发送电子邮件(请参阅文档)。

You need an SMTP server always - even in "php and other languages", but perhaps you don't know you need it, because it is bundled in your LAMP package. 您始终需要SMTP服务器-即使使用“ php和其他语言”也是如此,但是也许您不知道需要它,因为它捆绑在LAMP软件包中。

One solution is to use google as an SMTP server. 一种解决方案是将Google用作SMTP服务器。 Either via your account , or via google apps . 通过您的帐户 ,或通过Google Apps Otherwise setting up an smtp server (postfix for example) linux appears trivial, but isn't - you have to take into consideration many things - see this post by Jeff Atwood. 否则,设置一个smtp服务器(例如后缀)的linux看起来很简单,但不是-您必须考虑很多事情-请参阅Jeff Atwood的这篇文章

So ultimately, I'd suggest using the options provided by google. 因此,最终,我建议使用google提供的选项。

if you'r looking to host your own mail server, then apache james is a pretty good option. 如果您希望托管自己的邮件服务器,那么apache james是一个不错的选择。

or other solution could be using a third-party mailservers such as gmail or yahoo; 或其他解决方案可能使用的是第三方邮件服务器,例如gmail或yahoo; and use the JavaMail API to send emails. 并使用JavaMail API发送电子邮件。

If you don't have an SMTP server, Asprin is a send-only SMTP server, which is a pretty good fit. 如果您没有SMTP服务器,则Asprin是仅发送SMTP的服务器,非常合适。 It suffers from the same problem any do-it-yourself SMTP server will, in that it will look more like a Spam source, so using a proper SMTP server used for e-mail should be done if possible. 任何自己动手的SMTP服务器都会遇到相同的问题,因为它看起来更像是垃圾邮件源,因此,如果可能的话,应该使用用于电子邮件的正确SMTP服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM