【发布时间】:2013-04-10 23:30:50
【问题描述】:
我正在使用 XAMPP 在 tomcat 中部署我的 java 应用程序,还使用水银邮件发送电子邮件。现在我只是用一个使用 java 邮件 API 和水银电子邮件的小型 java 程序来测试我的应用程序。我已经在 Mercury 中完成了必要的配置来设置 localhost。我的程序运行成功,没有任何错误。 Mercury 日志文件也没有说明任何错误。
T 20130411 044359 51663963 Connection from 127.0.0.1
T 20130411 044359 51663963 EHLO 10.226.44.101
T 20130411 044359 51663963 MAIL FROM:<promil@localhost.com>
T 20130411 044359 51663963 RCPT TO:<*****@gmail.com>
T 20130411 044359 51663963 DATA
T 20130411 044359 51663963 DATA - 22 lines, 689 bytes.
T 20130411 044359 51663963 QUIT
T 20130411 044359 51663963 Connection closed with 127.0.0.1, 0 sec. elapsed.
这也是我的 java 文件....
public static void main(String [] args) {
// Recipient's email ID needs to be mentioned.
String to = "****@gmail.com";
// Sender's email ID needs to be mentioned
String from = "promil@localhost.com";
// Assuming you are sending email from localhost
String host = "localhost";
String password = "****";
// Get system properties
Properties properties = System.getProperties();
// Setup mail server
properties.setProperty("mail.smtp.host", host);
// Setup mail server
properties.setProperty("mail.smtp.password", password);
// Get the default Session object.
Session session = Session.getDefaultInstance(properties);
try{
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(from));
// Set To: header field of the header.
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
// Set Subject: header field
message.setSubject("This is the Subject Line!");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("This is message body");
// Create a multipar message
Multipart multipart = new MimeMultipart();
// Set text message part
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
String filename = "C:/Users/toshiba/Desktop/file.txt";
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
// Send the complete message parts
message.setContent(multipart );
// Send message
Transport.send(message);
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {
mex.printStackTrace();
}
我对此一无所知...... 我的 Mercury 核心进程还说它有 4 个待处理的传出工作......???
【问题讨论】:
-
您的问题不清楚。
RCPT TO:<*****@gmail.com>行表示您的邮件代理应将电子邮件转发到 gmail 地址,而不是在本地发送。如果是这种情况,Gmail 很可能会根据源 IP 地址丢弃邮件。 -
我把星星放在 RCPT TO: 中。我的问题是,如果日志文件和 java 文件都没有错误,那么我需要做些什么才能在我的 gmail acc 上接收电子邮件
-
在我看来,您的代码正在尝试连接到在 localhost 上运行的邮件服务器...您是否正在运行一个邮件服务器?
-
是的...XAMPP...它正在运行
-
你可能想试试这个视频:youtube.com/watch?v=_QnfF64rA78
标签: java xampp jakarta-mail