How to set envelope id in MailMessage class in C#? - c#

I want to implement automated email delivery tracking and I found out I could do this using the Delivery Status Notification and setting envelope id to track which email has been delivered/not delivered.
However I can't seem to find a way to set the envelope id parameter using the MailMessage class in C#. As I understand this parameter should go in the MAIL FROM header, something like:
MAIL FROM: RET=HDRS ENVID=QQ314159
I tried setting it using message.Headers.Add(), however when I receive the email and inspect its headers I don't see the envelope id in the 'From' header, as it gets it value from the message.From class property and I can't insert anything else than the email address there.
Can't find any information, anybody has some experience with this?

You can't actually do this with System.Net.Mail, but you can do it using MailKit:
http://www.mimekit.net/docs/html/M_MailKit_Net_Smtp_SmtpClient_GetEnvelopeId.htm

Related

How to get the message using message id in Mailkit?

I am using mail kit to send receive mail, and manage all records in my database. I am storing all user action for particular mail and then execute it using my code.
I am storing message id in the table for the unique message, now I want to get the message using messageid. Is there any way to do it?
Firstly, don't expect the Message-Id header to be globally unique. Any hacker could easily create their own message and re-use a known Message-Id to try and confuse software that depends on Message-Ids being unique.
That said, you'll need to use the IMailFolder.Search() API combined with SearchQuery.HeaderContains() to search for messages with a particular Message-Id header.
var uids = folder.Search (SearchQuery.HeaderContains ("Message-Id", "blah#blah.com"));

WPF - add userid as prefix to orignal mail while forwarding mail

I have textbox which shows the content of mail body.
While forwarding mail original mail body if content is edited by pressing any key then user id should get appended. Please let me know how should I do this in WPF.
Before sending the mail
if(edits_made) // bool value which indicates if changes have been made
{
yourtextbox.Text.Insert(0, userid);
}
Not before sending an mail.
Similar functionality is there in outlook as well.
Add < prefix to original mail if content is modified.
Same I am trying to build in WPF.

Using MailChimp for .NET sending mails to bcc

I'm using MailChimp for .NET sending mails, but the wrapper for the recipient doesn't contain a type, which the is necessary for sending massmails.
MailChimp.Types.Mandrill.Messages.Recipient recipient = new MailChimp.Types.Mandrill.Messages.Recipient(member.EMail, member.Name);
Is it me who has missed something?
Quoted from MailChimp. Scroll down to "Tips for creating your HTML Campaign".
MailChimp does not use a BCC field as each recipient on your list is hidden from all other recipients on your list. We deliver a completely separate copy of your email to each recipient on your list, allowing you to personalize your content for each recipient, track clicks and opens, and address each email to the recipient's name.
I decided to use MCAPI.NET and changed the source adding a attribute to Recipient with name "to".
Setting this attribute to value "BCC" solved the problem.
Note : MailChimp is a Newsletter sending software where Mandrill is a transactional mail sending component.

Implementing a mailing list in .NET

I am implementing a mailing list using using .NET. As discussed in this answer, I need to send an email where the recipient of the envelope is different from the recipient in the To header. How to achieve this in C#? The SmtpClient and MailMessage classes in System.Net.Mail doens't seem to permit this.
I tried:
message.To.Add("list#example.com");
message.Headers["Envelope-to"] = "user#example.com";
but the mail doesn't get sent to what it is specified in the Envelope-to.
Any suggestions?
Adding an address to Envelope-To without adding it to To
You can use the MailMessage.Bcc property. Addresses added there will only appear in the Envelope-To, not in the mail's To:
message.Bcc.Add("user#example.com");
Adding an address to To without adding it to Envelope-To
Here, I'm quite sure you are out of luck. I've had a look at the System.Net.Mail namespace with ILSpy, and it looks like this is not possible. The To header of the mail is created out of the To property of the MailMessage (see Message.PrepareHeaders), and the same property is used to fill the Envelope-To of the mail (together with the Cc and Bcc properties, see SmtpClient.Send). Manually setting Headers["To"] won't help, since this value is overwritten with the contents of the To property (see Message.PrepareHeaders).
So, list#example.com will get a copy of the message. Depending on the configuration of your SMTP server, this might lead to a mail loop.

How can I send emails to multiple recipients using a MailDefinition

I'm creating a new mail definition using the CreateMailMessage function of a MailDefinition. One of the required parameters is recipients. The documentation for this function states that recipients is to be a comma-separated list of recipients, however when I try to send a message to multiple users I am getting the following error:
An invalid character was found in the mail header: ','...
So it seems like this function is not working as intended. Normally I would add all the recipients to the mail message itself, but unfortunately the recipients parameter is required and cannot be left blank. Any ideas?
I got it working but unfortunately its more of a hack than anything.
I take one email address from the "to" field and set it as the recipient in CreateMailMessage, which returns a MailMessage instance.
I take the produced MailMessage and add all the email addresses in my MailAddressCollection by iterating through the construct. I also do this for all CC'd users.

Categories

Resources