Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. public bool SendEmail()
  2. {
  3. bool isSend = true;
  4. try
  5. {
  6. SmtpClient smtp = new SmtpClient();
  7. smtp.Host = "smtp.gmail.com";
  8. smtp.Port = 587;
  9. smtp.Credentials = new NetworkCredential("kips321786@gmail.com","umerzaman100");
  10. smtp.EnableSsl = true;
  11. MailAddress to = new MailAddress("m.umer.zaman@gmail.com");
  12. MailAddress from = new MailAddress("kips321786@gmail.com");
  13. MailMessage mail = new MailMessage(from, to);
  14. check = to.ToString();
  15. mail.Subject = "This is a Test Mail ";
  16. mail.Body = "WoW Mail is Receive";
  17. lblStatus.Text=" Sending email...";
  18. smtp.Send(mail);
  19. Thread.Sleep(10000);
  20. }
  21. catch (Exception e)
  22. {
  23. check = e.Message.ToString();
  24. isSend = false;
  25. }
  26. return isSend;
  27. }
  28.  
  29. public async void MailProccess(CancellationToken cancelToken =new CancellationToken())
  30. {
  31.  
  32. Task<bool> task2 = new Task<bool>(SendEmail);
  33. task2.Start();
  34. bool msg = await task2;
  35. if (msg)
  36. {
  37. lblStatus.Text = "Your Email Send....";
  38. }
  39. else
  40. {
  41. lblStatus.Text = "Your Email not Send....";
  42. }
  43. }
  44.  
  45. private void btnCancelEmail_Click(object sender, EventArgs e)
  46. {
  47. //Task.Factory.StartNew(() =>
  48. //{
  49. // if (cts.IsCancellationRequested)
  50. // {
  51. cts.Cancel();
  52. lblStatus.Text = "Email Sending Cancel";
  53. // }
  54. //});
  55.  
  56.  
  57. }
  58.  
  59. try{
  60. smtp.Send(mail);
  61. isSend = true;
  62. }
  63. catch(Exception ex)
  64. {
  65. isSend = false
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement