向 Web 应用程序添加电子邮件功能需要什么?
我有一个 java web 应用程序,我想向其添加电子邮件功能,但是,我不确定需要什么来完成此操作。具体来说,我希望我的应用程序能够:
- 发送确认注册的电子邮件
- 允许用户使用我的应用程序的域,即 发送电子邮件-protection" class="__cf_email__" data-cfemail="1377727d537e6a3e7263633d707c7e">[email protected]
根据我的研究,我似乎需要像 Postfix 这样的邮件传输代理(MTA),可能还需要像 Courier 这样的 IMAP 服务器;但我不明白 IMAP 服务器的必要性。
谢谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在网络应用程序中添加代码来创建电子邮件并将发送到 SMTP 世界。通常 JavaMail 用于此目的,您可以将其包含在 Web 应用程序中,或者(首选)让 Web 容器通过 JNDI 提供正确配置的实例。这是供应商特定的。
如果您没有可供 JavaMail 连接的 SMTP 服务器(通常是 Windows 商店的 Exchange),您可以运行一个服务器(询问您的 IT 管理员),或者使用 Google Mail 或 Hotmail 或其他适合您的邮件服务器。 Web 应用程序通过它们发送邮件。使用 GMail 作为 SMTP 服务器有点棘手,但如果设置正确,效果会很好。
您将需要 SMTP 服务器,因为它会处理有关 MX 记录的所有无聊细节,并在 SMTP 服务器执行灰名单等情况下重新发送。
哦,IMAP 用于获取已传递的邮件,而不是发送邮件。你不需要它。
You need code inside your web app to create and dispatch the email into the SMTP-world. Usually JavaMail is used for this, and you can either enclose it in your web application or (preferred) have the web container provide a correctly configured instance through JNDI. This is vendor specific.
If you do not have a SMTP-server for JavaMail to connect to (frequently this is Exchange for Windows shops), you can either get one running (ask your IT administrator) or use Google Mail or Hotmail or others if it is ok for your web application to send mail through them. It is a bit tricky to use GMail as a SMTP-server, but when set up correctly works very well.
You will need the SMTP-server, as it handles all the boring details regarding MX records and resending if the SMTP-server does graylisting, etc. etc.
Oh, and IMAP is for getting delivered mail, not sending mail. You don't need it.
如果它是一个 Java Web 应用程序,那么服务器部分就是一个 servlet。给定从客户端表单发送的电子邮件消息,您的服务器需要将该文本作为电子邮件发送出去。
Java EE 堆栈中有执行此操作的代码,或者您可以专门下载 JavaMail< /a>.这将允许您的程序充当邮件客户端。
您的 MTA 从 servlet 接收消息并将其发送给用户。到目前为止,一切都很好。
但是您还需要一个邮箱,即相当于用户的邮件收件箱。 Postfix、QMail 和其他提供了基本的“平面”邮箱模型,其中邮件被简单地存储,直到客户端接收它,然后(通常)删除。通过 POP3 访问。 IMAP 提供了更多的组织功能,即指定嵌套邮箱的层次结构、在它们之间传输邮件等的能力。您可能不想创建如此复杂的 GUI 前端,所以我猜您并不真正需要 IMAP 服务器。然而,您确实需要一个相对简单的 POP3 服务器来允许您的 servlet 通过 TCP/IP 访问邮箱。这通常是“标准”电子邮件服务器包的一部分。要让您自己的域为全世界所知,您需要访问 DNS 服务的 MX 记录,即您必须设置一两个主机,在面向互联网的地址上,作为您的邮局。
最后,如果您想省去很多麻烦,请在配置 MTA(SMTP 服务器)时非常小心,以免它被用作开放中继。也就是说,您的用户一般不可能向外界发送邮件(否则黑客会找到一种方法来滥用您的 Web 界面来执行此操作),并且来自 Internet 的邮件不应到达您的用户。最重要的是,互联网上的邮件不应该被转发到互联网上的其他地方。查找在网上开放中继测试服务(它们是免费的),并在您认为完成后找人对您的配置进行测试。
编辑:
查看 Thorbjorn 的回答,我意识到您可能不希望用户通过您的应用程序接收邮件;他们可能已经拥有自己的电子邮件提供商和帐户。在这种情况下,您无需担心收件箱功能或 POP3 服务器。您可以考虑在您的域中提供完整的电子邮件服务,但这是一项非常吃力不讨好的工作,如果您有任何选择,请将这项肮脏的工作留给 GMail、雅虎、Hotmail 及其同类。无论您提供什么服务都永远无法让您的客户满意,而且您每天都将与垃圾邮件和其他犯罪作斗争。
If it's a Java web app, then the server part is a servlet. Given an email message sent from a client form, your server needs to send that text off as an email.
There's code in the Java EE stack to do this, or you can specifically download JavaMail. This will allow your programs to act as mail clients.
Your MTA receives messages from your servlet and sends them to the users. So far so good.
But you also need a postbox, i.e. the equivalent of a mail in-box for your users. Postfix, QMail and others offer a basic "flat" mailbox model, where mail is simply stored until the client picks it up, and then (usually) deleted. Access is via POP3. IMAP offers a lot more organizational capability, i.e. the ability to specify hierarchies of nested mailboxes, to transfer mails between them and so on. You probably won't want to create a GUI front end to all that complexity, so I'd guess you don't really need an IMAP server. You do, however, want a relatively simple POP3 server to allow your servlet to access the mailboxes via TCP/IP. This is usually part of the "standard" email server packages.To have your own domain known to the world, you need access to the MX records of your DNS service, i.e. you have to set up one or two of your hosts, on an Internet-facing address, to be your post office.
Finally, if you want to save yourself a lot of trouble, be very careful in configuring your MTA (SMTP server) such that there is no chance for it being used as an open relay. i.e. it should not be possible for your users to send mail to the outside world in general (or hackers will find a way to abuse your Web interface to do this), and mail from the Internet should not reach your users. Most importantly, there should be no way for mail from the Internet to be forwarded to someplace else in the Internet. Find an open relay testing service (they're free) on the 'net and get one to run a test on your configuration once you think you're done.
EDIT:
Looking at Thorbjorn's answer, I realized you probably don't want your users receiving their mail through your app; they probably already have email providers and accounts of their own. In that case, you don't need to worry about inbox capability or a POP3 server. You could consider offering full email services at your domain but that's a very thankless job and if you have any choice, leave that dirty work to GMail, Yahoo, Hotmail and their ilk. Whatever service you provide will never please your customers enough, and you'll be fighting spam and other crime every day.
首先,您的服务器必须具有邮件功能。在 Linux 领域,sendmail 通常就是这样。
另外,请查看 javaMail。
http://www.oracle.com/technetwork/java/index- jsp-139225.html
For starters your server has to have mailing abilities. In linux land sendmail is usually what this will be.
Additionally, check out javaMail.
http://www.oracle.com/technetwork/java/index-jsp-139225.html