3

私は、電子メールまたは電子メールが正常に配信されたかどうかの可能な手段を介して確認を取得しようとしている単純な 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");
        }

    }

}

私は正しい軌道に乗っていますか?何か他のものを参照する必要がありますか? Delivery Status Notification について詳しく調べようとしましたが、これまでのところ実際の例を見つけることができませんでした。

4

1 に答える 1

1

いいね。SMTP サーバーが配信ステータス通知をサポートしていることを確認してください。

telnet を使用して送信するEHLOだけで十分です。DSN を出力する必要があります。何かのようなもの

[root@blah ~]$ telnet localhost 25
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 blah ESMTP Sendmail 8.14.3/8.14.3/Debian-9.1ubuntu1; Fri, 28 Jun 2013 10:30:28 -0400; (No UCE/UBE) logging access from: localhost(OK)-localhost [127.0.0.1]
EHLO toto
250-blah Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
于 2013-06-28T14:32:25.370 に答える