kaisellgren / mailer

Compose and send emails from Dart. Supports file attachments, HTML emails and multiple transport methods.
MIT License
168 stars 87 forks source link

ReplyTo #188

Closed mohamad-elbohsaly closed 3 years ago

mohamad-elbohsaly commented 3 years ago

Let's say I send a message from the company email to a recipient1 CCing another recipient2. Can I do a replyTo: recipient2?

close2 commented 3 years ago

You can add your custom headers:

  final equivalentMessage = Message()
    ..from = Address(username, 'Your name 😀')
    ..recipients.add(Address('destination@example.com'))
    ..ccRecipients.addAll([Address('destCc1@example.com'), 'destCc2@example.com'])
    ..bccRecipients.add('bccAddress@example.com')
    ..subject = 'Test Dart Mailer library :: 😀 :: ${DateTime.now()}'
    ..text = 'This is the plain text.\nThis is line 2 of the text part.'
    ..html = '<h1>Test</h1>\n<p>Hey! Here is some HTML content</p><img src="cid:myimg@3.141"/>'
    ..headers = { 'Reply-To', Address('recipient2@example.com', "Rec 2") }
    ..attachments = [
      FileAttachment(File('exploits_of_a_mom.png'))
        ..location = Location.inline
        ..cid = '<myimg@3.141>'
    ];

I have added a headers line to the example code above:
..headers = { 'Reply-To', Address('recipient2@example.com', "Rec 2") }

The address in the reply-to can be any address. It's not necessary to add the reply-to address to the CC list.