I've got this method here, I wanted to go e.Mail.To = MAC, but apparently it's a read only property, which leaves me completely stumped on how I can programmatically set the recipients. Basically I want to change the to address based on my deployment level (live/test/dev) I also want to dispose() (not send) the email for dev/test modes.
Is there another way round this?
public static void ErrorMail_Mailing(object sender, ErrorMailEventArgs e)
{
if (!GlobalHelper.IsLiveMode)
{
e.Mail.Dispose();
}
else
{
MailAddressCollection MAC = new MailAddressCollection();
MAC.Add("A");
}
Following snippet will 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("[email protected]");
MAC.Add("[email protected]");
e.Mail.To.Clear(); // Clears any existing mail addresses if you want to
e.Mail.To.Add(MAC.ToString()); // To contains [email protected] & [email protected]
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With