How to programmatically configure an email recipient Elma

I have this method here, I wanted to go e.Mail.To = MAC, but apparently this is a read-only property that leaves me completely at a standstill on how I can programmatically set recipients. Basically I want to change the address based on my deployment level (live / test / dev). I also want to send () (not send) an email to dev / test.

Is there another way?

public static void ErrorMail_Mailing(object sender, ErrorMailEventArgs e)
        {
            if (!GlobalHelper.IsLiveMode)
            {
                e.Mail.Dispose();
            }
            else
            {
                MailAddressCollection MAC = new MailAddressCollection();
                MAC.Add("A");

            }
+5
source share
1 answer

The following snippet will help solve your problem -

public static void ErrorMail_Mailing(object sender, ErrorMailEventArgs e)         
{             
    if (!GlobalHelper.IsLiveMode)             
    {                 
        e.Mail.Dispose();             
    }             
    else         
    {                 
        MailAddressCollection MAC = new MailAddressCollection();                 
        MAC.Add("A@XYZ.COM");              
        MAC.Add("B@XYZ.COM");              



        e.Mail.To.Clear(); // Clears any existing mail addresses if you want to
        e.Mail.To.Add(MAC.ToString()); // To contains A@XYZ.COM & B@XYZ.COM
    } 
}
+4
source

All Articles