aleksander frnczak
aleksander frnczak

Reputation: 449

can't set "To" and "Subject" headers in imap append

I am building app where i send email to client with nodemailer and after that i want to add copy of that email to SENT mailbox on email client. The emails are added properly but without subject and header. I am using imap-simple package and I was following examples in docs, not sure why is that happening

I am connecting with imap to home.pl mailbox

imaps
      .connect(imapConfig)
      .then((connection) => {
        const message = `Content-Type: text/html;charset=utf-8
        From:[email protected]
        To: ${email}
        Subject:Wniosek o e-recepte wysłany
        \r\n
        ${email}
      `;

        connection.append(message, {
          mailbox: "SENT",
          flags: "\\Sent",
        });
        return null;
      })
      .catch((err) => {
        console.log(err);
      });

Upvotes: 0

Views: 419

Answers (1)

arnt
arnt

Reputation: 9685

The spaces before From, To and Subject aren't legal. You can use spaces almost anywere, these three are legal:

From: [email protected]
From : [email protected]
From:      [email protected]

But spaces before the From ungood. When something other than a header field name follows a CR, most parsers consider the header to end and the mail body to start. (Which is perhaps not quite comme il faut, I don't remember that part of the formal grammar. But someone who sends a buggy message cannot complain if parsers choose a different buggy interpretation than intended.)

Upvotes: 1

Related Questions