我正在尝试编写一个测试,它将使用JavaMail SMTP或SMTPS通过SSL和身份验证向我正在运行的Greenmail服务器发送消息.
我写了一个快速的小子,它应该完全符合我的要求:
import java.util.Properties;
import javax.mail.Session;
import javax.mail.Transport;
import com.icegreen.greenmail.user.GreenMailUser;
import com.icegreen.greenmail.util.GreenMail;
public class MailTest {
public static void main(String[] args) throws Exception {
GreenMail greenmail = new GreenMail();
try {
greenmail.start();
String email = "foo@bar";
String userid = "user";
String password = "pa$$word";
GreenMailUser setUser = greenmail.setUser(email, userid, password);
setUser.create();
GreenMailUser user = greenmail.getManagers().getUserManager().getUser(userid);
System.out.println("User created:" + user.getEmail() + ":" + user.getLogin() + ":" + user.getPassword());
int portSmtps = greenmail.getSmtps().getPort();
System.out.println("Smtps started on port:" + portSmtps); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Greenmail来测试我的localhost上的电子邮件功能.问题是我没有安装SMTP服务器,并且认为安装一个SMTP服务器过度.我的期望是应该有一个免费的库,允许我保持我的发送邮件代码相同,但不是真正发送电子邮件到SMTP服务器,发送到我的本地机器,以便我可以检索它们(为了单位)测试).
我曾经使用Grails开发时曾使用Greenmail,而且体验很棒.但我找不到类似于Spring Framework的东西.在Greenmail页面中,它说有一个与JBoss捆绑在一起的模拟 SMTP服务器.但我不想运行JBoss,因为目前我的Web应用程序正在Tomcat上运行.
Tomcat有没有类似的服务?或者有没有更好的方法将测试电子邮件发送到localhost,我可以在哪里检索发送的电子邮件?
更新:
我尝试使用Ralph的方法,但它仍然产生相同的异常:
[SimpleAsyncTaskExecutor-1] 2012-03-13 10:19:39,475 - ERROR: com.test.my.service.emailing.impl.EmailServiceImpl - Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 3025;
nested exception is:
java.net.ConnectException: Connection refused: connect. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 3025;
nested exception is:
java.net.ConnectException: Connection refused: connect
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 3025;
nested …Run Code Online (Sandbox Code Playgroud) 我有一个使用骆驼发送电子邮件的应用程序。我们的环境中设置了一个绿色邮件服务器。测试服务的测试人员需要能够查看发送的电子邮件,以验证 html 格式是否正确。似乎没有一种明显的方法可以将浏览器指向绿色邮件服务器来查看电子邮件。请注意,我们使用 wildfly,而带有 wildfly 和 dockers 的 JMX 并不可靠。除了jmx还有什么吗?