1

I using golang with emersion/go-smtp and gomail to send mail. It working fine to send email to account. But I have some problem I cannot send email with reply that email who send to me.

For example,

A(Sender) send mail to B(Me) I can get messageID of A mail with IMAP. I try to send reply mail with In-Reply-To and References with sender messageID mail. Unfortunately it send email to new mail (not ref with A mail)

Some code and header I setup to send mail.

gomail

    // Set E-Mail sender
    m.SetHeader("From", "me@mail.com")

    // Set E-Mail receivers
    m.SetHeader("To", "sender@mail.com")

    m.SetHeader("In-Reply-To", "<messageID of A mail>")

    m.SetHeader("References", "<messageID of A mail>")

    // Set E-Mail subject
    m.SetHeader("Subject", "reply mail")

    // Set E-Mail body. You can set plain text or html with text/html
    m.SetBody("text/plain", "test reply mail")

emersion/go-smtp

msg := strings.NewReader(
    "In-Reply-To: <messageID of A mail>\r\n" +
        "To: sender@mail.com\r\n" +
        "References: <messageID of A mail>\r\n" +
        "Subject: reply mail\r\n" +
        "\r\n" +
        "test reply mail\r\n")
Rawit_S
  • 43
  • 6
  • 1
    So, on the receiving end, you have verified that the generated message does indeed have the `In-Reply-To` and `References` header fields (using any suitable MUA program), have you? I mean, the question per se does not present a tangible problem as it may easily be with the way _a program you're using displays mails,_ and not with the mail message contents or the way it is sent. That is, you did not yet debug it completely, and everything we can say is something like "uh, looks like there is _some_ problem…". – kostix Mar 24 '21 at 14:58
  • 4
    Your email client may be treating it as a new mail because of the subject. Some will ignore "In-Reply-To" if the subject isn't "Re: ". As far as how email itself works, *every* email is "a new email"; "conversations" are a concept created by email *clients*, but don't exist natively in email. – Adrian Mar 24 '21 at 15:11
  • 1
    @Adrian That work! Thank a lot you save my day. – Rawit_S Mar 25 '21 at 07:07

0 Answers0