1

我目前正在开发一个小型 Java 程序,该程序应该从我的地址向我的地址发送一封通用电子邮件。我使用 XAMPP Mercury 作为 smtp 服务器。当我运行程序时,代码显示“成功发送消息......”但我的邮箱保持为空。这是我的代码:

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendEmail
{
   public static void main(String [] args)
   {    
      // Recipient's email ID needs to be mentioned.
      String to = "Basti-V@web.de";

      // Sender's email ID needs to be mentioned
      String from = "Basti-V@web.de";

      // Assuming you are sending email from localhost
      String host = "localhost";

      // Get system properties
      Properties properties = System.getProperties();

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

      // 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!");

         // Now set the actual message
         message.setText("This is actual message");

         // Send message
         Transport.send(message);
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }
}

我没有使用 Mercury 的经验,所以可能是配置错误。我希望有人比我更了解。

编辑:通过使用 setDebug

    DEBUG: setDebug: JavaMail version 1.4.5
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "localhost", port 25, isSSL false
220 127.0.0.1 ESMTP server ready.
DEBUG SMTP: connected to host "localhost", port: 25

EHLO Bastian-TOSH
250-127.0.0.1 Hello Bastian-TOSH; ESMTPs are:
250-TIME
250-SIZE 0
250 HELP
DEBUG SMTP: Found extension "TIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg "0"
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<Basti-V@web.de>
250 Sender OK - send RCPTs.
RCPT TO:<Basti-V@web.de>
250 Recipient OK - send RCPT or DATA.
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   Basti-V@web.de
DATA
354 OK, send data, end with CRLF.CRLF
From: Basti-V@web.de
To: Basti-V@web.de
Message-ID: <1028214719.0.1458570595718.JavaMail.Bastian@Bastian-TOSH>
Subject: This is the Subject Line!
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is actual message
.
250 Data received OK.
QUIT
221 127.0.0.1 Service closing channel.
Sent message successfully....
4

0 回答 0