Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The code below does what you want, and does it in the correct way. Reread what you yourself posted in the comment</p> <blockquote> <p>From: <a href="http://www.ietf.org/rfc/rfc2821.txt" rel="noreferrer">RFC2821: 4.4 Trace Information</a></p> <p>When the delivery SMTP server makes the "final delivery" of a message, it inserts a return-path line at the beginning of the mail data. This use of return-path is required; mail systems MUST support it. The return-path line preserves the information in the from the MAIL command. Here, final delivery means the message has left the SMTP environment. Normally, this would mean it had been delivered to the destination user or an associated mail drop, but in some cases it may be further processed and transmitted by another mail system.</p> </blockquote> <p>and a few lines later.</p> <blockquote> <p>A message-originating SMTP system SHOULD NOT send a message that already contains a Return-path header.</p> </blockquote> <p>If you carefully read this you will understand that only the final smtp-server/delivery agent is supposed to add the <code>Return-Path</code> header. It is not something you as client (trying to send a mail) should do. The final smtp-server will base the <code>Return-Path</code> header on the sender address of the envelope (<code>SMTP MAIL FROM</code> part).</p> <p>So setting <code>mail.smtp.from</code> is the correct way to tell java that the envelope sender address should be different from the <code>from</code> part.</p> <p>If you have troubles understanding what the different <code>from</code>'s are just take a look at a telnet smtp-session. Where <code>replyto@example.com</code> should correspond to <code>smtp.mail.from</code> and <code>from@example.com</code> to <code>m.addFrom(...);</code></p> <pre><code>telnet smtp.example.com 25 220 smtp.example.com ESMTP ..... helo computername 250 smtp.example.com Hello computername [123.123.123.123] mail from:&lt;replyto@example.com&gt; 250 &lt;replyto@example.com&gt; is syntactically correct rcpt to:&lt;rcpt@foo.com&gt; 250 &lt;rcpt@foo.com&gt; verified data 354 Enter message, ending with "." on a line by itself To: Joey &lt;to@joey.com&gt; From: Joey &lt;from@example.com&gt; Subject: Joey Hey Joey! . 250 OK id=.... Quit </code></pre> <hr> <pre><code>props.put("mail.smtp.from", "replyto@example.com"); Session session = Session.getDefaultInstance(props, null); MimeMessage m = new MimeMessage(session); m.addFrom(InternetAddress.parse("from@example.com")); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload