Exemplo n.º 1
0
 public void SendCDO(string to)
 {
     try
     {
         CDO.Message        msg = new CDO.Message();
         CDO.IConfiguration iConfig;
         iConfig = msg.Configuration;
         ADODB.Fields oFields;
         oFields = iConfig.Fields;
         ADODB.Field oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
         //oField.Value = 2;
         //oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
         //oField.Value = "smtp.gmail.com";
         //oField = oFields["http://schemas.microsoft.com/cdo/configuration/stmpserverport"];
         //oField.Value = 25;
         oFields.Update();
         msg.Subject  = "Prueba";
         msg.From     = "*****@*****.**";
         msg.To       = to;
         msg.TextBody = "Mensaje de pueba";
         msg.Send();
         Console.WriteLine("Mensaje enviado");
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Sends an email via G-Mail with the provided email settings.
        /// </summary>
        /// <param name="fromEmailAddress"></param>
        /// <param name="toEmailAddress"></param>
        /// <param name="subject"></param>
        /// <param name="messageBody"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static void send(string fromEmailAddress, string fromName, string toEmailAddress, string subject, string messageBody, string password, string server, int port, int timeout)
        {
            CDO.Message       smtp       = new CDO.Message();
            CDO.Configuration smtpConfig = new CDO.Configuration();

            ADODB.Fields fieldCollection = smtpConfig.Fields;
            ADODB.Field  serverField     = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
            serverField.Value = server;
            ADODB.Field usernameField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/sendusername"];
            usernameField.Value = fromEmailAddress;
            ADODB.Field passwordField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/sendpassword"];
            passwordField.Value = password;
            ADODB.Field authField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"];
            authField.Value = 1;
            ADODB.Field timeoutField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"];
            timeoutField.Value = timeout;
            ADODB.Field serverPortField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
            serverPortField.Value = port;
            ADODB.Field sendUsingField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/sendusing"];
            sendUsingField.Value = 2;
            ADODB.Field useSSLField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpusessl"];
            useSSLField.Value = 1;
            fieldCollection.Update();

            smtp.Configuration = smtpConfig;
            smtp.Subject       = subject;
            smtp.From          = fromEmailAddress;
            smtp.To            = toEmailAddress;
            smtp.Sender        = fromName;
            smtp.Organization  = fromName;
            smtp.ReplyTo       = fromEmailAddress;
            smtp.TextBody      = messageBody;
            smtp.Send();
        }
Exemplo n.º 3
0
        private void LoadExtraDataForView()
        {
            try
            {
                if (this._array.Count > 0)
                {
                    ADODB.Connection cnn = new ADODB.Connection();
                    ADODB.Recordset  rs  = new ADODB.Recordset();
                    ADOX.Catalog     cat = new ADOX.Catalog();

                    // Open the Connection
                    cnn.Open(dbRoot.ConnectionString, null, null, 0);
                    cat.ActiveConnection = cnn;

                    rs.Source = cat.Views[this.View.Name].Command;
                    rs.Fields.Refresh();
                    ADODB.Fields flds = rs.Fields;

                    Column col = this._array[0] as Column;

                    f_TypeName = new DataColumn("TYPE_NAME", typeof(string));
                    col._row.Table.Columns.Add(f_TypeName);

                    f_AutoKey = new DataColumn("AUTO_INCREMENT", typeof(Boolean));
                    col._row.Table.Columns.Add(f_AutoKey);

                    Column      c   = null;
                    ADODB.Field fld = null;

                    int count = this._array.Count;
                    for (int index = 0; index < count; index++)
                    {
                        fld = flds[index];
                        c   = (Column)this[fld.Name];

                        c._row["TYPE_NAME"]      = fld.Type.ToString();
                        c._row["AUTO_INCREMENT"] = false;
                    }

                    rs.Close();
                    cnn.Close();
                }
            }
            catch {}
        }
Exemplo n.º 4
0
        /// <summary>
        /// 邮件通过465端口发送会不成功,微软的System.Net.Mail类只支持 “Explicit SSL”,目前通过CDO的方式来实现,需要在IIS上做对应配置
        /// </summary>
        /// <param name="to"></param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        public static void SendBy(string to, string subject, string body)
        {
            CDO.Message        oMsg    = new CDO.Message();
            CDO.IConfiguration iConfg  = oMsg.Configuration;
            ADODB.Fields       oFields = iConfg.Fields;

            ADODB.Field oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
            oField.Value = CDO.CdoSendUsing.cdoSendUsingPort;

            oField       = oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"];
            oField.Value = CDO.CdoProtocolsAuthentication.cdoBasic;

            oField       = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
            oField.Value = "smtp.exmail.qq.com";

            oField       = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
            oField.Value = 465;

            oField       = oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"];
            oField.Value = "*****@*****.**";

            oField       = oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"];
            oField.Value = "ZKTD51robotjob";

            oField       = oFields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"];
            oField.Value = "true";



            oMsg.TextBody = body;
            oMsg.Subject  = subject;
            oMsg.From     = "*****@*****.**";
            oMsg.To       = to;
            try
            {
                oMsg.Send();
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 5
0
        private void EnviarCDO(Email email)
        {
            String msgSenha = Decrypt.Executar(_config.SmtpSenha);

            CDO.Message        message       = new CDO.Message();
            CDO.IConfiguration configuration = message.Configuration;
            ADODB.Fields       fields        = configuration.Fields;
            ADODB.Field        field         = fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
            field.Value = _config.SmtpServer;
            field       = fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
            field.Value = _config.Porta;
            field       = fields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
            field.Value = CDO.CdoSendUsing.cdoSendUsingPort;
            field       = fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"];
            field.Value = CDO.CdoProtocolsAuthentication.cdoBasic;
            field       = fields["http://schemas.microsoft.com/cdo/configuration/sendusername"];
            field.Value = _config.SmtpUser;
            field       = fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"];
            field.Value = msgSenha;
            field       = fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"];
            field.Value = _config.EnableSsl ? "true" : "false";
            fields.Update();

            List <string> lstArquivos = CopyTempPath(email);

            lstArquivos.ForEach(x => message.AddAttachment(x));

            message.From     = _config.Remetente;
            message.To       = email.Destinatario.Replace(';', ',');
            message.Subject  = email.Assunto;
            message.HTMLBody = email.Texto;

            try
            {
                message.Send();
            }
            finally
            {
                lstArquivos.ForEach(x => System.IO.File.Delete(x));
                string path = GerarDirTemp(email.Id);
            }
        }
Exemplo n.º 6
0
        static public bool Helper_SendEmail(string Tos, string Subject, string Message)
        {
            string From = "*****@*****.**"; //HARDCODED

            System.Net.Mail.SmtpClient vSmtpClient;
            vSmtpClient = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["SMTP_SERVER"], Convert.ToInt32(ConfigurationManager.AppSettings["SMTP_PORT"]));

            vSmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            vSmtpClient.Credentials    = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["SMTP_USERNAME"], ConfigurationManager.AppSettings["SMTP_PASSWORD"]);
            vSmtpClient.EnableSsl      = true;

            try
            {
                //System.Net.Mail.MailMessage vMessage;
                //vMessage = new System.Net.Mail.MailMessage();

                //string[] tab_Tos = Tos.Split(new char[] {','});
                //foreach(string To in tab_Tos)
                //    if(!string.IsNullOrWhiteSpace(To))
                //        vMessage.To.Add(To);
                ////vMessage.To.Add("*****@*****.**");  //HARDCODED
                //vMessage.Bcc.Add("*****@*****.**");   //HARDCODED
                ////"*****@*****.**"
                //vMessage.From = new System.Net.Mail.MailAddress(From);
                //vMessage.Subject = Subject;
                //vMessage.IsBodyHtml = true;
                //vMessage.Body = Message;
                //vMessage.Priority = System.Net.Mail.MailPriority.Normal;
                //vSmtpClient.Send(vMessage);

                CDO.Message        message       = new CDO.Message();
                CDO.IConfiguration configuration = message.Configuration;
                ADODB.Fields       fields        = configuration.Fields;

                ADODB.Field field = fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
                field.Value = ConfigurationManager.AppSettings["SMTP_SERVER"];

                field       = fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
                field.Value = 465;

                field       = fields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
                field.Value = CDO.CdoSendUsing.cdoSendUsingPort;

                field       = fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"];
                field.Value = CDO.CdoProtocolsAuthentication.cdoBasic;

                field       = fields["http://schemas.microsoft.com/cdo/configuration/sendusername"];
                field.Value = ConfigurationManager.AppSettings["SMTP_USERNAME"];

                field       = fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"];
                field.Value = ConfigurationManager.AppSettings["SMTP_PASSWORD"];

                field       = fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"];
                field.Value = "true";

                fields.Update();

                Utils.Helper_Trace("Email Service", String.Format("Building CDO Message..."));

                message.From = From;
                string[] tab_Tos = Tos.Split(new char[] { ',' });
                foreach (string To in tab_Tos)
                {
                    if (!string.IsNullOrWhiteSpace(To))
                    {
                        message.To = To;  //TODO
                    }
                }
                message.Subject  = Subject;
                message.TextBody = Message;


                // Send message.
                message.Send();
            }
            catch (Exception ex)
            {
                Utils.Helper_Trace("Email Service", "Error sending email to the administrator : " + ex.Message + " " + ex.InnerException);
                return(false);
            }

            Utils.Helper_Trace("XORCISM Email Service", "Email sent");
            return(true);
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            try
            {
                //MailMessage mail = new MailMessage(new MailAddress("*****@*****.**"), new MailAddress("*****@*****.**"));
                //mail.Sender = new MailAddress("*****@*****.**");
                //mail.IsBodyHtml = true;
                //mail.Subject = "this is a test email.";
                //mail.Body = "this is my test email body";


                //SmtpClient client = new SmtpClient();
                //client.DeliveryMethod = SmtpDeliveryMethod.Network;
                //client.UseDefaultCredentials = false;
                //client.Credentials = new NetworkCredential("*****@*****.**", "Mv_d_LuM1JBY2O_EqGe_xQ");
                //client.EnableSsl = true;
                //client.Port = 587;
                //client.Host = "smtp.mandrillapp.com";
                //client.Send(mail);

                CDO.Message        oMsg = new CDO.Message();
                CDO.IConfiguration iConfg;

                iConfg = oMsg.Configuration;

                ADODB.Fields oFields;
                oFields = iConfg.Fields;

                // Set configuration.
                ADODB.Field oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
                oField.Value = 2;

                oField       = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
                oField.Value = "smtp.mandrillapp.com";

                oField       = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
                oField.Value = 587;

                oField       = oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"];
                oField.Value = 1;

                oField       = oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"];
                oField.Value = "*****@*****.**";

                oField       = oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"];
                oField.Value = "Mv_d_LuM1JBY2O_EqGe_xQ";

                oField       = oFields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"];
                oField.Value = false;

                oField       = oFields["http://schemas.microsoft.com/cdo/configuration/subject"];
                oField.Value = "test";

                oFields.Update();

                // Set common properties from message.

                oMsg.TextBody = "test";


                //String sHtml;
                //sHtml = "<HTML>\n" +
                //    "<HEAD>\n" +
                //    "<TITLE>Sample GIF</TITLE>\n" +
                //    "</HEAD>\n" +
                //    "<BODY><P>\n" +
                //    "<h1><Font Color=Green>Inline graphics</Font></h1>\n" +
                //    "</BODY>\n" +
                //    "</HTML>";

                oMsg.HTMLBody             = "";
                oMsg.HTMLBodyPart.Charset = "UTF-8";
                oMsg.BodyPart.Charset     = "UTF-8";

                //TOTO: To send WEb page in an e-mail, uncomment the following lines and make changes in TODO section.
                //TODO: Replace with your preferred Web page
                //oMsg.CreateMHTMLBody("http://www.microsoft.com",
                //	CDO.CdoMHTMLFlags.cdoSuppressNone,
                //	"", "");
                oMsg.Subject = "test";


                //TODO: Change the To and From address to reflect your information.
                oMsg.From = "*****@*****.**";
                oMsg.To   = "*****@*****.**";
                //ADD attachment.
                //TODO: Change the path to the file that you want to attach.
                //oMsg.AddAttachment("C:\\Hello.txt", "", "");
                //oMsg.AddAttachment("C:\\Test.doc", "", "");
                oMsg.Send();
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 8
0
        public static void SendBy(string to, string subject, string body)
        {
            CDO.Message        oMsg    = new CDO.Message();
            CDO.IConfiguration iConfg  = oMsg.Configuration;
            ADODB.Fields       oFields = iConfg.Fields;

            ADODB.Field oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
            oField.Value = CDO.CdoSendUsing.cdoSendUsingPort;

            oField       = oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"];
            oField.Value = CDO.CdoProtocolsAuthentication.cdoBasic;

            oField       = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
            oField.Value = "smtp.exmail.qq.com";

            oField       = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
            oField.Value = 465;

            oField       = oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"];
            oField.Value = "*****@*****.**";

            oField       = oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"];
            oField.Value = "ZKTD51robotjob";

            oField       = oFields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"];
            oField.Value = "true";



            oMsg.TextBody = body;
            oMsg.Subject  = subject;
            oMsg.From     = "*****@*****.**";
            oMsg.To       = to;
            try
            {
                oMsg.Send();
            }
            catch (Exception)
            {
                throw;
            }
            //MailMessage mailMessage = new MailMessage();
            //mailMessage.To.Add("*****@*****.**");
            //mailMessage.From = new MailAddress("*****@*****.**");
            //mailMessage.Subject = subject;
            //mailMessage.Body = body;
            //mailMessage.IsBodyHtml = true;

            ////需要读取配置
            //SmtpClient client = new SmtpClient("smtp.exmail.qq.com", 465)
            //{
            //    EnableSsl = true
            //};
            //client.Credentials = new NetworkCredential("*****@*****.**", "ZKTD51robotjob");
            ////ConfigurationManager.AppSettings["user"].ToString(),
            ////ConfigurationManager.AppSettings["password"].ToString());

            //try
            //{
            //    client.Send(mailMessage);
            //    //LoggerHelper.Writelog(
            //    //    string.Format("Email发送成功,发送给:{0},发送标题为:{1},发送内容为:{2}", to, subject, body),
            //    //    LogLevel.Info);
            //}
            //catch (Exception ex)
            //{
            //    //LoggerHelper.Writelog(ex.Message, LogLevel.Error);
            //}
        }
Exemplo n.º 9
0
        /// <summary>
        /// Send Mail
        /// </summary>
        /// <returns></returns>
        public NotifyComResponse Send()
        {
            NotifyComResponse notifyComResponse = new NotifyComResponse();

            try
            {
                try
                {
                    MailAddress ma = new MailAddress(_fromAddress);
                }
                catch (FormatException ex)
                {
                    // invalid from mail address, set it to [email protected]
                    LogBook.Write("The format for the from email address (" + _fromAddress + ") is incorrect. [email protected] will be used instead.");
                    _fromAddress = "*****@*****.**";
                }

                SmtpClient ss = new SmtpClient(_smtpServer, _smtpPort);


                MailMessage mm = new MailMessage(_fromAddress, _toAddress, _subject, _body);

                CDO.Message message = new CDO.Message();
                /*Create Mail Message Object*/
                MailMessage mailObj = new MailMessage();
                /*Email from address*/
                mailObj.From = new MailAddress(_fromAddress, _fromName);
                /*Email to address*/
                mailObj.To.Add(new MailAddress(_toAddress));
                /*Email subject*/
                mailObj.Subject = _subject;
                /*Email Body Encoding*/
                mailObj.BodyEncoding = Encoding.Default;
                /*Email Body*/
                mailObj.Body = _body;
                /*Body format (HTML/Text)*/
                mailObj.IsBodyHtml = _isBodyHTML;

                /*Via SMTP Gateway (i.e. your local Exchange Server)-> SmtpSendMethod = 0*/
                /*Via Direct Domain SMTP Connection w/DNS MX Lookup-> SmtpSendMethod = 1*/
                /*When SmtpSendMethod = 1 we are sending via local host instead of using SMTP settings*/
                SmtpClient smtpClientObj = null;
                if (_sendMethod == 1)
                {
                    //Send message
                    string domain = mailObj.To[0].Address.Substring(mailObj.To[0].Address.IndexOf('@') + 1);
                    //To Do :need to check for MX record existence before you send. Left intentionally for you.
                    string mxRecord = SendSMTP.DnsLookUp.GetMXRecords(domain)[0];
                    smtpClientObj = new SmtpClient(mxRecord);
                }
                else
                {
                    if (_isTLS == true && _isSSL == false)
                    {
                        ss.EnableSsl             = true;
                        ss.Timeout               = 20000;
                        ss.DeliveryMethod        = SmtpDeliveryMethod.Network;
                        ss.UseDefaultCredentials = false;
                        ss.Credentials           = new NetworkCredential(_smtpAuthUserName, _smtpAuthPassword);

                        mm.BodyEncoding = UTF8Encoding.UTF8;
                        mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                        mm.IsBodyHtml = _isBodyHTML;
                    }
                    else
                    {
                        CDO.IConfiguration configuration = message.Configuration;
                        ADODB.Fields       fields        = configuration.Fields;


                        ADODB.Field field = fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
                        field.Value = _smtpServer;

                        field       = fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
                        field.Value = _smtpPort;

                        field       = fields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
                        field.Value = CDO.CdoSendUsing.cdoSendUsingPort;

                        field = fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"];

                        if (_smtpAuthMethod == "" || _smtpAuthMethod.ToUpper() == "NONE")
                        {
                            field.Value = CDO.CdoProtocolsAuthentication.cdoAnonymous;
                        }
                        else if (_smtpAuthMethod.ToUpper() == "NTLM")
                        {
                            field.Value = CDO.CdoProtocolsAuthentication.cdoNTLM;
                        }
                        else
                        {
                            field.Value = CDO.CdoProtocolsAuthentication.cdoBasic;
                        }

                        field       = fields["http://schemas.microsoft.com/cdo/configuration/sendusername"];
                        field.Value = _smtpAuthUserName;

                        field       = fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"];
                        field.Value = _smtpAuthPassword;

                        field       = fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"];
                        field.Value = _isSSL;

                        field       = fields["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"];
                        field.Value = 10;

                        fields.Update();

                        message.From    = @"""" + _fromName + @""" <" + _fromAddress + ">";;
                        message.To      = _toAddress;
                        message.Subject = _subject;
                        if (_isBodyHTML)
                        {
                            message.HTMLBody = _body;
                        }
                        else
                        {
                            message.TextBody = _body;
                        }
                    }
                }

                try
                {
                    if (_sendMethod == 1)
                    {
                        smtpClientObj.Send(mailObj);
                    }
                    else
                    {
                        /*Send Mail*/
                        if (_isTLS == true && _isSSL == false)
                        {
                            ss.Send(mm);
                        }
                        else
                        {
                            message.Send();
                        }
                    }

                    /*Record notify response*/
                    notifyComResponse.IsError         = false;
                    notifyComResponse.IsSucceeded     = true;
                    notifyComResponse.ResponseContent = "Email sent to: " + "[" + _emailToName + "]" + _toAddress + ((_isAlphaPager) ? " (ALPHA PAGER) " : "");
                }
                catch (Exception ex)
                {
                    /*Record notify response*/
                    notifyComResponse.IsError         = true;
                    notifyComResponse.IsSucceeded     = false;
                    notifyComResponse.ResponseContent = "Email to: " + "[" + _emailToName + "]" + _toAddress + ((_isAlphaPager) ? " (ALPHA PAGER) " : "") + " Failed " + ex.Message;

                    /*Debug Object values for reference*/
                    LogBook.Debug(notifyComResponse, this);

                    /*Write exception log*/
                    LogBook.Write("Error has occurred while sending email to ." + _emailToName, ex, "CooperAtkins.NotificationServer.NotifyEngine.Email.EmailClient");
                }
                finally
                {
                    // Added on 2/19/2012
                    // Srinivas Rao Eranti
                    // Added try catch to release the message object
                    try
                    {
                        Marshal.FinalReleaseComObject(message);
                        // GC.SuppressFinalize(message);
                    }
                    catch
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                /*Record notify response*/
                notifyComResponse.IsError         = true;
                notifyComResponse.IsSucceeded     = false;
                notifyComResponse.ResponseContent = "Email to: " + "[" + _emailToName + "]" + _toAddress + ((_isAlphaPager) ? "(ALPHA PAGER)" : "") + " Failed " + ex.Message;


                /*Debug Object values for reference*/
                LogBook.Debug(notifyComResponse, this);

                /*Write exception log*/
                LogBook.Write("Error has occurred while preparing SMTP setting.", ex, "CooperAtkins.NotificationServer.NotifyEngine.Email.EmailClient");
            }
            return(notifyComResponse);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Send an electronic message using the Collaboration Data Objects (CDO).
        /// </summary>
        /// <remarks>http://support.microsoft.com/kb/310212</remarks>
        private static bool SendUsingYahoo(MailMessage m, string userName, string password)
        {
            try
            {
                CDO.Message        message       = new CDO.Message();
                CDO.IConfiguration configuration = message.Configuration;
                ADODB.Fields       fields        = configuration.Fields;

                // Set configuration.
                // sendusing:               cdoSendUsingPort, value 2, for sending the message using the network.
                // smtpauthenticate:     Specifies the mechanism used when authenticating to an SMTP service over the network.
                //                                  Possible values are:
                //                                  - cdoAnonymous, value 0. Do not authenticate.
                //                                  - cdoBasic, value 1. Use basic clear-text authentication. (Hint: This requires the use of "sendusername" and "sendpassword" fields)
                //                                  - cdoNTLM, value 2. The current process security context is used to authenticate with the service.

                ADODB.Field field = fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
                field.Value = "smtp.mail.yahoo.com";

                field       = fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
                field.Value = 465;

                field       = fields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
                field.Value = CDO.CdoSendUsing.cdoSendUsingPort;

                field       = fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"];
                field.Value = CDO.CdoProtocolsAuthentication.cdoBasic;

                field       = fields["http://schemas.microsoft.com/cdo/configuration/sendusername"];
                field.Value = userName;

                field       = fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"];
                field.Value = password;

                field       = fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"];
                field.Value = "true";

                fields.Update();

                message.From    = userName;
                message.To      = string.Join(",", m.To.Select(a => a.Address));
                message.Subject = m.Subject;
                if (m.IsBodyHtml)
                {
                    message.HTMLBody = m.Body;
                }
                else
                {
                    message.TextBody = m.Body;
                }

                message.Send();
                if (Log.IsDebugEnabled)
                {
                    Log.Debug("Email sent successfully.");
                }
                return(true);
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Error sending email to {0}.", string.Join(",", m.To.Select(a => a.Address)));
                Log.Error(ex.Message, ex);
            }
            return(false);
        }