简体   繁体   English

在Linux环境中如何使用Java发送邮件?

[英]How to send mail using Java in a Linux environment?

I have successfully sent mail using Java using apache james server in Windows. 我已经在Windows中使用apache james服务器使用Java成功发送了邮件。 I have been trying to do the same in Linux, but couldn't start the james server. 我一直在尝试在Linux中执行相同的操作,但是无法启动james服务器。 I am a novice in Linux. 我是Linux的新手。

Is james server really necessary for sending mails? 詹姆斯服务器真的需要发送邮件吗? If so how to start james server in Linux? 如果是这样,如何在Linux中启动james服务器?

For sending emails in java you can use the java mail api: http://www.oracle.com/technetwork/java/javamail/index.html 要使用Java发送电子邮件,您可以使用Java邮件api: http : //www.oracle.com/technetwork/java/javamail/index.html
See this tutorial for infos about using it: http://www.tutorialspoint.com/java/java_sending_email.htm 有关使用它的信息,请参见本教程: http : //www.tutorialspoint.com/java/java_sending_email.htm

They are using a mail server on localhost, but i wouldn't recommend that. 他们在本地主机上使用邮件服务器,但我不建议这样做。 It is perfectly alright for testing or if your localhost is a server with proper DNS records. 如果您要进行测试,或者您的本地主机是具有正确DNS记录的服务器,则完全可以。 If you send emails from a IP where DNS reverse lookup does not work, chances are that your mail will be stopped by a spam filter. 如果您从无法进行DNS反向查找的IP发送电子邮件,则很有可能被垃圾邮件过滤器阻止您的邮件。

If you want a mailserver on localhost you could install exim, postfix, ssmtp or any other MTA from your linux distribution. 如果要在本地主机上安装邮件服务器,则可以从Linux发行版中安装exim,postfix,ssmtp或任何其他MTA。 It's possible that one of them is already installed and running. 其中之一可能已经安装并正在运行。

I would use some other mail server for example the one you are using to send emails. 我会使用其他一些邮件服务器,例如您用于发送电子邮件的服务器。 This line of code from the tutorial configures the host: 本教程中的以下代码行配置主机:

  // Setup mail server
  properties.setProperty("mail.smtp.host", host);

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

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