I did an smt email sending using C# program. The problem i am facing is my pop is not coming. when i press the button. Email is sending properly and the form is closing also.
I want the email to send first and then popup to display, then the application need to closed. But at this moment email is sent perfectly and form is closing. When i remove the this.close()
the pop up is coming and email is sending, but form..:-(.
How to resolve this issue.
My codes
private void button7_Click(object sender, EventArgs e)
{
//System.Threading.Thread.Sleep(4000);
SmtpClient client = new SmtpClient("smtp.gmail.com", 25);
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("stacy1983@gmail.com", "sorrynopass");
MailMessage msg = new MailMessage();
msg.To.Add("jack.margret@gmail.com");
msg.From = new MailAddress("stacy1983@gmail.com");
msg.Subject = ("hello good");
msg.Body = ("congo");
client.Send(msg);
taskbarNotifier3.CloseClick+=new EventHandler(CloseClick);
taskbarNotifier3.Show("Email Successfully Sent!!!", "GOOB BYE!!!.", 500, 3000, 500);
this.Hide();
System.Timers.Timer aTimer = new System.Timers.Timer(3000);
aTimer.Elapsed += OnTimedEvent;
aTimer.Enabled = true;
}
private void CloseClick(object sender, EventArgs e)
{
this.Close();
}
private void OnTimedEvent(Object source, ElapsedEventArgs e)
{
this.Close();
}
// Error called Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on.