我有一个简单的 java 邮件代码,我试图通过电子邮件或通过任何可能的方式确认电子邮件是否成功发送,现在我已经尝试了以下代码,电子邮件发送正常,只是我无法获得交货确认。
import java.io.File;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import com.sun.mail.smtp.SMTPMessage;
import net.htmlparser.jericho.Source;
public class SmtpMail {
/**
* @param args
*/
public static void main(String[] args) {
String to = "amit.jadhav@myorg.com"; //both emails are valid
String from = "reciever@sample.com";
String host = "relay.myorg.com";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.transport.protocol", "SMTP");
Session session = Session.getDefaultInstance(properties);
SMTPMessage smtpMessage = new SMTPMessage(session);
try {
smtpMessage.setSender(new InternetAddress(from));
smtpMessage.setRecipient(Message.RecipientType.TO,
new InternetAddress(to));
smtpMessage.setSubject("Hello Test Email");
smtpMessage.setText("Test Email to check Delivery Report");
smtpMessage.setReturnOption(SMTPMessage.RETURN_FULL);
smtpMessage.setNotifyOptions(SMTPMessage.NOTIFY_SUCCESS);
Transport.send(smtpMessage);
} catch (Exception e) {
System.out.println("Error while building smpt email");
}
}
}
我在正确的轨道上吗?我需要参考别的东西吗?我试图了解有关交付状态通知的更多信息,但到目前为止还没有找到一个可行的示例。