示例#1
0
 private bool SendMail(string to, string subject, string url, MailConfig pmc)
 {
     DateTime before = DateTime.Now;
     try
     {
         CDO.Message msg = new CDO.Message();
         CDO.Configuration conf = msg.Configuration;
         Fields fs = conf.Fields;
         #region Set field values
         fs["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value = "hu";
         fs["http://schemas.microsoft.com/cdo/configuration/postusing"].Value = CdoPostUsing.cdoPostUsingPort;
         fs["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = pmc.sendemailaddress;
         fs["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = pmc.sendpassword;
         fs["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = pmc.sendusername;
         fs["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CdoSendUsing.cdoSendUsingPort;
         fs["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value = "Zoznam";
         fs["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = CdoProtocolsAuthentication.cdoBasic;
         fs["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"].Value = 10;
         fs["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = pmc.smtpserver;
         fs["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = pmc.smtpport;
         fs["http://schemas.microsoft.com/cdo/configuration/usemessageresponsetext"].Value = true;
         fs["http://schemas.microsoft.com/cdo/configuration/smtpusessl"].Value = false;
         fs["urn:schemas:calendar:timezoneid"].Value = CdoTimeZoneId.cdoEasternEurope;
         #endregion
         fs.Update();
         msg.Subject = subject;
         Trace.WriteLine("Downloading email body from feed page...");
         lblSendStatus.Text = "Send status: Downloading email body from feed page...";
         msg.CreateMHTMLBody(url, CdoMHTMLFlags.cdoSuppressNone, null, null);
         msg.To = to;
         Trace.WriteLine("Sending message...");
         lblSendStatus.Text = "Send status: Sending message...";
         msg.Send();
         TimeSpan total = DateTime.Now.Subtract(before);
         Trace.WriteLine("Message sent successfully. Total time: " + total.ToString());
         lblSendStatus.Text = "Send status: Message sent successfully. Total time: " + total.ToString();
         return true;
     }
     catch (COMException cex)
     {
         Trace.WriteLine(cex.ToString());
         return false;
     }
 }