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("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
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.