Implementing a mailing list in .NET - c#

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.

Related

C# Mail - Separate Sender and Return Path

I am attempting to set a different return path and sender in the headers to replicate a previous PHP system. It needs to be exactly the same.
When I put in a Sender it sets this to the return path and I can't seem to find a solution to separate these. Also the sender shows as behalf of in the From part of the mail message which I do not want.
Any recommendations?
Use:
MailMessage mail = new MailMessage("sender#email.com", "to#email.com");
mail.ReplyToList.Add(new MailAddress("reply#email.com", "reply-to"));
Please note MailMessage.ReplyTo is now obsolete.
Documentation
Have a look at the MailMessage.ReplyTo property.
Use the ReplyTo property to indicate an address other than the From address to use to reply to this message.
I used the MailKit library to solve my issue.
This allows you to specify a different sender at server level

How to set envelope id in MailMessage class in 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

Internal addresses are missing after MSG to EML conversion using Redemption

I am currently evaluating the redemption library for converting MSG files to EML files.
RDOSession session = new RDOSession();
RDOMail msg = session.GetMessageFromMsgFile(msgFile);
msg.SaveAs(emlFile, rdoSaveAsType.olRFC822);
So far Redemption is doing a really good job here in contrast to everything else I've tested against our "wild MSG-files corpus".
Nevertheless there is an issue with internal e-mail addresses. For internal e-mail addresses the resulting EML-file does contain the personal part of the addresses only but not the real e-mail address with the # sign.
I can see that RDOMail's recipient objects contains the real e-mail address in the SMTPAddress property in any case.
But there is a difference for the Address property which contains the "real e-mail address" for external addresses but something like /O=EXAMPLE ORGANIZAION/OU=SOME GROUP/cn=Recipients/cn=FBarney for internal addresses.
The latter ones are exactly the addresses that are missing the real e-mail address in the resulting EML-file.
So I tried to override the Address property like that:
recipient.Address = recipient.SMTPAddress;
But this does not have any effect on the resulting EML-file at the end.
How to convert MSG to EML with redemption without losing the real e-mail addresses for internal addresses?
This is an indication that EX type addresses cannot be converted to SMTP. This usually happens if the current MAPI session does not have access to the Exchange server that hosts these GAL objects. In your particular case, there is no MAPI session at all. You can either set the RDOSession.MAPIOBJECT property to Namespace.MAPIOBJECT from the Outlook Object Model to share the session with Outlook or you can call RDOSession.Logon/LogonExchangeMailbox/etc.
You can also try to specify the olRfc822_Redemption format to force Redemption to use its internal MIME convertor (it jumps through quite a few hoops to get the SMTP addresses from the message itself rather than GAL). By default olRfc822 uses the built-in Outlook convertor (IConvertorSession) if Outlook is installed.

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.

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