protected override void Cancel(AsyncCodeActivityContext context) { SendMailAsyncResult sendMailAsyncResult = (SendMailAsyncResult)context.UserState; sendMailAsyncResult.Client.SendAsyncCancel(); }
protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state) { MailMessage message = new MailMessage(); message.From = this.From.Get(context); if (TestMailTo.Expression == null) { foreach (MailAddress address in this.To.Get(context)) { message.To.Add(address); } MailAddressCollection ccList = this.CC.Get(context); if (ccList != null) { foreach (MailAddress address in ccList) { message.CC.Add(address); } } MailAddressCollection bccList = this.Bcc.Get(context); if (bccList != null) { foreach (MailAddress address in bccList) { message.Bcc.Add(address); } } } else { message.To.Add(TestMailTo.Get(context)); } Collection <Attachment> attachments = this.Attachments.Get(context); if (attachments != null) { foreach (Attachment attachment in attachments) { message.Attachments.Add(attachment); } } if (!string.IsNullOrEmpty(this.BodyTemplateFilePath)) { LoadBodyTemplate(context); } if ((this.Tokens.Get(context) != null) && (this.Tokens.Get(context).Count > 0)) { ReplaceTokensInBody(context); } if (this.TestMailTo.Expression != null) { AddTestInformationToBody(context); } message.Subject = this.Subject.Get(context); message.Body = this.Body; SmtpClient client = new SmtpClient(); client.Host = this.Host; client.Port = this.Port; client.EnableSsl = this.EnableSsl; if (string.IsNullOrEmpty(this.UserName)) { client.UseDefaultCredentials = true; } else { client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential(this.UserName, this.Password); } if (!string.IsNullOrEmpty(this.TestDropPath)) { WriteMailInTestDropPath(context); } var sendMailAsyncResult = new SendMailAsyncResult(client, message, callback, state); context.UserState = sendMailAsyncResult; return(sendMailAsyncResult); }
public IAsyncResult BeginExecute(AsyncCallback callback, object state) { SendMailAsyncResult sendMailAsyncResult = null; try { MailMessage message = new MailMessage(); message.From = this.From; if (TestMailTo == null) { foreach (MailAddress address in this.To) { message.To.Add(address); } MailAddressCollection ccList = this.CC; if (ccList != null) { foreach (MailAddress address in ccList) { message.CC.Add(address); } } MailAddressCollection bccList = this.Bcc; if (bccList != null) { foreach (MailAddress address in bccList) { message.Bcc.Add(address); } } } else { message.To.Add(TestMailTo); } List <Attachment> attachments = this.Attachments; if (attachments != null) { foreach (Attachment attachment in attachments) { message.Attachments.Add(attachment); } } if (!string.IsNullOrEmpty(this.BodyTemplateFilePath)) { LoadBodyTemplate(); } if ((this.Tokens != null) && (this.Tokens.Count > 0)) { ReplaceTokensInBody(); } if (this.TestMailTo != null) { AddTestInformationToBody(); } message.Subject = this.Subject; message.Body = this.Body; message.IsBodyHtml = true; SmtpClient client = new SmtpClient(); ////client.EnableSsl = this.EnableSsl; //if (string.IsNullOrEmpty(this.UserName)) //{ // client.UseDefaultCredentials = true; //} //else //{ // client.UseDefaultCredentials = false; // client.Credentials = new NetworkCredential(this.UserName, this.Password); //} //if (!string.IsNullOrEmpty(this.TestDropPath)) //{ // WriteMailInTestDropPath(context); //} sendMailAsyncResult = new SendMailAsyncResult(client, message, callback, state); } catch (System.Exception ex) { } //context.UserState = sendMailAsyncResult; return(sendMailAsyncResult); }