muratgozel / MIMEText

RFC-2822, RFC-2045 and RFC-2049 compliant raw email message generator.
https://muratgozel.github.io/MIMEText/
MIT License
82 stars 35 forks source link

Add a Reply-To header #45

Closed julbrs closed 9 months ago

julbrs commented 1 year ago

Hi,

It seems that we are struggling to add a "Reply-To" header (which is different from the "From" header). What is the best way to define a "Reply-To"?

const message = createMimeMessage();
message.setHeader('Reply-To', contact.email);

generate the following message:

MIMETEXT_INVALID_HEADER_VALUE: You specified an invalid value for the header Reply-To

Thanks!

ryan-vaneck commented 1 year ago

I am also seeing this issue

yukikywong commented 1 year ago

I also see the same problem with setting the Sender header.

const message = createMimeMessage();
message.setHeader("Sender", "test@example.com");

When setting "Sender", it is validating if the value is an instance of a Mailbox. When I try to import Mailbox however

import { createMimeMessage, Mailbox } from "mimetext";

I can only import the Mailbox interface but not the class, so I cannot call the Mailbox constructor to create a Mailbox.

Gowee commented 1 year ago

Inspired by @yukikywong, this idea comes up to me:

message.setHeader("Reply-To", createMimeMessage().setSender("test@example.com"));

where setSender just returns a Mailbox instance.

It does work well even though be tricky.

xriter commented 1 year ago

@Gowee This seems to be a working solution for now. A dedicated message.setReplyTo({ name: ..., addr: ... }) would be more elegant though.

muratgozel commented 9 months ago

Inspired by @yukikywong, this idea comes up to me:

message.setHeader("Reply-To", createMimeMessage().setSender("test@example.com"));

where setSender just returns a Mailbox instance.

It does work well even though be tricky.

yo what? how did you even come up with this, this is smart hahah

sorry for the delay, im taking care of it right now

muratgozel commented 9 months ago

hey again, the Reply-To header is specially handled by the lib and proper way to add it is by creating an instance of Mailbox: msg.setHeader('Reply-To', new Mailbox('asd@asd.com')) as its just become available as of version v3.0.19. you have to import the Mailbox class: import { createMimeMessage, Mailbox } from 'mimetext'. closing this issue as it should all be resolved, open again if you face any problems.