protected SmtpClient GetClient(SmtpItem si) { SmtpClient smtpClient = new SmtpClient(si.SmtpServer, si.Port); if (si.NeedsAuth) { smtpClient.Credentials = new NetworkCredential(si.Username, si.Password); smtpClient.EnableSsl = si.UseSsl; } return(smtpClient); }
public void PerformSend(object stateInfo) { bool flag = true; foreach (KeyValuePair <SmtpItem, Tuple <DateTime, Queue <IScrapeResult> > > current in this.tsks) { if (current.Value.Value.Count > 0) { SmtpItem key = current.Key; SmtpClient client = this.GetClient(key); client.SendCompleted += new SendCompletedEventHandler(this.SendCompleted); this.pendingCount++; IScrapeResult scrapeResult = null; Queue <IScrapeResult> value; Monitor.Enter(value = current.Value.Value); try { scrapeResult = current.Value.Value.Dequeue(); } finally { Monitor.Exit(value); } string email = scrapeResult.GetEmail(); MailMessage mailMessage = this.GetMailMessage(key.EmailAddress, email); flag = false; try { if (this.ErrorCallback != null) { this.ErrorCallback.Log(string.Format("Sending message to {0} from {1}", email, key.EmailAddress)); } client.SendAsync(mailMessage, new KeyValuePair <IScrapeResult, SmtpItem>(scrapeResult, key)); } catch (Exception arg_EE_0) { Exception exception = arg_EE_0; if (this.ErrorCallback != null) { this.ErrorCallback.Log(exception.Message); } this.ProcessSendCompleted(new KeyValuePair <IScrapeResult, SmtpItem>(scrapeResult, key), false); } } } if (flag && this.pendingCount <= 0) { this.Stop(); } }
public void Send(SmtpItem si, MailMessage email) { SmtpClient client = this.GetClient(si); client.Send(email); }