I am using RadNotification control to show the results of sending emails.
Emails are being sent asynchronously and I want to trigger a notification on the async callback. When I try to change the notification text from this function, it does not change it on the notification, showing the initially set message.
Any suggestions? Here is my c# code:
protected void SendEmail(string Subject, string MessageBody, string EmailList)
{
MailMessage mail = new MailMessage();
//set the addresses
string SelectedEmails = "";
mail.From = new MailAddress("noreply@domain.com");
string[] Emails = EmailList.Split(';');
foreach (string Email in Emails)
{ //remove duplicates
if (SelectedEmails.IndexOf(Email) == -1)
{ mail.To.Add(Email);
SelectedEmails +="; "+ Email;}
}
//set the content
mail.Subject = Subject;
mail.Body = MessageBody;
//send the message
SmtpClient smtp = new SmtpClient();
Object userState = mail;
//Attach event handler for async callback
smtp.SendCompleted += new SendCompletedEventHandler(smtpClient_SendCompleted);
//Send the email asynchronously
smtp.SendAsync(mail, userState);
}
protected void smtpClient_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
//Get UserState as MailMessage instance from SendMail()
MailMessage mailMessage = e.UserState as MailMessage;
if (e.Cancelled)
{
ShowNotification("Sending of email message was cancelled. Address=" + mailMessage.To[0].Address);
}
if (e.Error != null)
{
ShowNotification("Error occured, info=" + e.Error.Message);
}
else
{
string EmailRecepients = "";
int count = mailMessage.To.Count;
for (int i = 0; i < count; i++)
{
EmailRecepients += "\r\n" + mailMessage.To[i].Address;
}
ShowNotification("Notification was sent successfully to:" + EmailRecepients);
}
}
protected void ShowNotification(string NotifcationText)
{
RadNotification1.Text = NotifcationText;
RadNotification1.Show();
}
Emails are being sent asynchronously and I want to trigger a notification on the async callback. When I try to change the notification text from this function, it does not change it on the notification, showing the initially set message.
Any suggestions? Here is my c# code:
protected void SendEmail(string Subject, string MessageBody, string EmailList)
{
MailMessage mail = new MailMessage();
//set the addresses
string SelectedEmails = "";
mail.From = new MailAddress("noreply@domain.com");
string[] Emails = EmailList.Split(';');
foreach (string Email in Emails)
{ //remove duplicates
if (SelectedEmails.IndexOf(Email) == -1)
{ mail.To.Add(Email);
SelectedEmails +="; "+ Email;}
}
//set the content
mail.Subject = Subject;
mail.Body = MessageBody;
//send the message
SmtpClient smtp = new SmtpClient();
Object userState = mail;
//Attach event handler for async callback
smtp.SendCompleted += new SendCompletedEventHandler(smtpClient_SendCompleted);
//Send the email asynchronously
smtp.SendAsync(mail, userState);
}
protected void smtpClient_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
//Get UserState as MailMessage instance from SendMail()
MailMessage mailMessage = e.UserState as MailMessage;
if (e.Cancelled)
{
ShowNotification("Sending of email message was cancelled. Address=" + mailMessage.To[0].Address);
}
if (e.Error != null)
{
ShowNotification("Error occured, info=" + e.Error.Message);
}
else
{
string EmailRecepients = "";
int count = mailMessage.To.Count;
for (int i = 0; i < count; i++)
{
EmailRecepients += "\r\n" + mailMessage.To[i].Address;
}
ShowNotification("Notification was sent successfully to:" + EmailRecepients);
}
}
protected void ShowNotification(string NotifcationText)
{
RadNotification1.Text = NotifcationText;
RadNotification1.Show();
}