private void cmdCheckServer_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; SmtpClientExt client = new SmtpClientExt(param.STMPserver, param.STMPport, param.EmailUserId, param.EmailPassword, string.Empty, chkLogEmail.Checked, ckbDoNotSendEmail.Checked, new CallBackStatus(PrintRegel)); this.Cursor = Cursors.Arrow; }
private void DoSomeWork(object status) { errorList = new StringBuilder(); errorMail = false; string sSource = "MultiMail"; string sLog = "Application"; errorList.AppendLine("Email not sent to:"); IProgressCallback callback = status as IProgressCallback; try { callback.Begin(0, clbLeden.CheckedItems.Count + clbExtraEmail.CheckedItems.Count); SmtpClientExt client = new SmtpClientExt(param.STMPserver, param.STMPport, param.EmailUserId, param.EmailPassword, EmailLogFile, chkLogEmail.Checked, ckbDoNotSendEmail.Checked, callback.SetText); MailMessage message = new MailMessage(); message.Subject = txtSubject.Text; message.From = new MailAddress(param.EmailReturnAdress); message.ReplyToList.Add(param.EmailReturnAdress); message.IsBodyHtml = ckbHtml.Checked; string messid = string.Format("<{0}@{1}>", Guid.NewGuid().ToString(), "wwww.ttvn.nl"); message.Headers.Add("Message-Id", messid); string strBody = string.Empty; if (ckbHtml.Checked) { strBody = string.Format(@"<html><head><meta http-equiv=Content-Type content=""text/html; charset=us-ascii""></head>{0}</html>", htmlTextbox1.Text); } else { strBody = htmlTextbox1.PlainText; } if (txtBijlage1.Text != string.Empty) { //emailer.Attachments.Add(new SmtpAttachment(txtBijlage1.Text)); message.Attachments.Add(new Attachment(txtBijlage1.Text)); } if (txtBijlage2.Text != string.Empty) { //emailer.Attachments.Add(new SmtpAttachment(txtBijlage2.Text)); message.Attachments.Add(new Attachment(txtBijlage2.Text)); } if (txtBijlage3.Text != string.Empty) { //emailer.Attachments.Add(new SmtpAttachment(txtBijlage3.Text)); message.Attachments.Add(new Attachment(txtBijlage3.Text)); } for (int i = 0; i < clbLeden.Items.Count; i++) { if (!clbLeden.GetItemChecked(i)) { continue; } message.To.Clear(); message.To.Add(clbLeden.Items[i].ToString()); message.Body = MailRoutines.ReplaceKeyWords(strBody, ledenSchaduwlijst[i], param); //emailer.To.Clear(); //emailer.To.Add(clbLeden.Items[i].ToString()); //emailer.Body = MailRoutines.ReplaceKeyWords(strBody, ledenSchaduwlijst[i], param); try { //emailer.SendMessage(); client.Send(message); } catch (Exception ex) { try { if (!EventLog.SourceExists("MultiMail")) { EventLog.CreateEventSource(sSource, sLog); } EventLog.WriteEntry(sSource, ex.Message + @"/n" + message.Body, EventLogEntryType.Warning, 001); } catch (Exception ex2) { GuiRoutines.ExceptionMessageBox(this, ex); Console.WriteLine(ex2.ToString()); } errorMail = true; errorList.AppendLine(clbLeden.Items[i].ToString()); } callback.Increment(1); callback.SetText(clbLeden.Items[i].ToString()); System.Threading.Thread.Sleep(50); if (callback.IsAborting) { return; } } for (int i = 0; i < clbExtraEmail.Items.Count; i++) { if (!clbExtraEmail.GetItemChecked(i)) { continue; } message.To.Clear(); message.To.Add(clbExtraEmail.Items[i].ToString()); message.Body = MailRoutines.ReplaceKeyWords(strBody, new tblLid(), param); try { client.Send(message); } catch (Exception ex) { try { if (!EventLog.SourceExists("MultiMail")) { EventLog.CreateEventSource(sSource, sLog); } EventLog.WriteEntry(sSource, ex.Message, EventLogEntryType.Warning, 001); } catch { } errorMail = true; errorList.AppendLine(clbExtraEmail.Items[i].ToString()); } callback.Increment(1); callback.SetText(clbExtraEmail.Items[i].ToString()); System.Threading.Thread.Sleep(50); if (callback.IsAborting) { return; } } callback.WaitOK(); } catch (System.Threading.ThreadAbortException ex) { // We want to exit gracefully here (if we're lucky) try { if (!EventLog.SourceExists("MultiMail")) { EventLog.CreateEventSource(sSource, sLog); } EventLog.WriteEntry(sSource, ex.Message, EventLogEntryType.Warning, 001); } catch { } } catch (System.Threading.ThreadInterruptedException ex) { // And here, if we can try { if (!EventLog.SourceExists("MultiMail")) { EventLog.CreateEventSource(sSource, sLog); } EventLog.WriteEntry(sSource, ex.Message, EventLogEntryType.Warning, 001); } catch { } } catch (Exception ex) { try { if (!EventLog.SourceExists("MultiMail")) { EventLog.CreateEventSource(sSource, sLog); } EventLog.WriteEntry(sSource, ex.Message, EventLogEntryType.Warning, 001); } catch { } GuiRoutines.ExceptionMessageBox(this, ex); } finally { if (callback != null) { callback.End(); } } }
private void SendInschrijfIncassoAankondiging() { string fileName = param.LocationTemplates + @"\Template_InschrijfIncasso.htm"; if (!File.Exists(fileName)) { MessageBox.Show("Template voor inschrijfgeldincasso mail " + fileName + " bestaat niet", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SmtpClientExt client = new SmtpClientExt(param.STMPserver, param.STMPport, param.EmailUserId, param.EmailPassword, EmailLogFile, chkLogEmail.Checked, ckbDoNotSendEmail.Checked, callback.SetText); //SmtpEmailer emailer = new SmtpEmailer(); //emailer.Host = param.STMPserver; //emailer.From = param.EmailReturnAdress; //emailer.AuthenticationMode = AuthenticationType.Base64; //emailer.User = param.EmailUserId; //emailer.Password = param.EmailPassword; //emailer.LogFile = EmailLogFile; //emailer.DoNotSendMail = ckbDoNotSendEmail.Checked; //emailer.LogMail = chkLogEmail.Checked; StreamReader sr = File.OpenText(fileName); StringReader str = new StringReader(sr.ReadToEnd()); string template = str.ReadToEnd(); foreach (Leden.Net.tblRekening rekening in selectedInc) { MailMessage message = new MailMessage(); message.From = new MailAddress(param.EmailReturnAdress); //emailer.ClearMessage(); if (rekening.TypeRekening == 0) { continue; // Geen Contributie incasso's } string sbr = template; //vervangen sbr = MailRoutines.ReplaceKeyWords(sbr, rekening.Lid, param); sbr = ReplaceRekeningItems(sbr, rekening); message.Body = sbr; //emailer.Body = sbr; if (rekening.Lid.MainEmailAdress != string.Empty) { message.Subject = "Aankondiging incasso TTVN"; //emailer.Subject = "Aankondiging incasso TTVN"; message.To.Add(rekening.Lid.MainEmailAdress); //emailer.To.Add(rekening.Lid.MainEmailAdress); } else { message.Subject = "Geen email adres bij Aankondiging incasso TTVN"; //emailer.Subject = "Geen email adres bij Aankondiging incasso TTVN"; message.To.Add(param.EmailReturnAdress); //emailer.To.Add(param.EmailReturnAdress); } message.IsBodyHtml = true; //emailer.SendAsHtml = true; try { client.Send(message); //emailer.SendMessage(); } catch { errorMail = true; errorList.AppendLine(rekening.Lid.MainEmailAdress); } callback.Increment(1); callback.SetText(rekening.Lid.MainEmailAdress); System.Threading.Thread.Sleep(50); if (callback.IsAborting) { return; } } }