我需要使用JavaMail发送简单的html消息。当我试图在互联网上找到一些很好的例子和解释,每一个下一个例子都让我更加生气和愤怒。如何配置环境以使用JavaMail?
所有这些愚蠢的例子包含复制和粘贴它们的差别仅在评论和一个不错的声明,首先,你应该配置你的SMTP和POP3服务器的Java代码。
据我所知,没有人愿意让一个做广告的一些具体产品,但配置的服务器是恕我直言最难的部分。那么,任何人都可以给我一些关于配置具体服务器(例如Kerio或其他任何一个)的非常有用的信息(无需Java代码)?
我现在有什么是下一个异常:
250 2.0.0 Reset state
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Relaying to <[email protected]> denied (authentication required)
UPD。以前所有文本的简单重写是:想象你有Windows,jdk,而没有别的。你想制作java程序并在你的机器上运行它。这个程序应该发送“Hello world!”到您的Gmail帐户。列出你的步骤。
UPD2。下面是代码:
Properties props = new Properties();
props.setProperty ("mail.transport.protocol", "smtp");
props.setProperty ("mail.host", "smtp.gmail.com");
props.setProperty ("mail.user", "[email protected]");
props.setProperty ("mail.password", "password_from_email_above");
Session mailSession = Session.getDefaultInstance (props, null);
mailSession.setDebug (true);
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage (mailSession);
message.setSubject ("HTML mail with images");
message.setFrom (new InternetAddress ("[email protected]"));
message.setContent ("<h1>Hello world</h1>", "text/html");
message.addRecipient (Message.RecipientType.TO,
new InternetAddress ("[email protected]"));
transport.connect();
transport.sendMessage (message,
message.getRecipients (Message.RecipientType.TO));
和异常是:
RSET
250 2.1.5 Flushed 3sm23455365fge.10
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. 3sm23455365fge.10
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1829)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1368)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:886)
at com.teamdev.imgmail.MailSender.main(MailSender.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
...
你的问题太含糊回答,因为它代表。请告诉我们更多关于您的主机及其上运行的组件的信息。继续品牌,我们不在乎。告诉我们你想做什么,什么是工作,什么不是。 – 2009-12-22 12:23:53
@Carl Smotricz:我加了UPD部分。 – Roman 2009-12-22 12:29:48
更新是一个*更*更好的问题。为此,事实证明,您甚至不需要自己的SMTP服务器,因为Google恰好为您运行一个相当大的服务器。 – 2009-12-22 12:32:50