Esempio n. 1
3
        /// <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();
        }
Esempio n. 2
2
        public int SendMail(MailAccount Sender, MailAccount Receiver, string mailSubject)
        {
            //获得要处理的邮件信
            try
            {

                string mailUser = Sender.UserName;
                string mailPass = Sender.Password;
                string mailFrom = Sender.UserName;
                string smtpserver = Sender.SmtpHost;

                CDO.Message message = new CDO.Message();

                message.To = Receiver.UserName;
                message.TextBody = "Test Send";
                //邮件标题
                message.Subject = "Test";
                message.From = Sender.UserName;
                message.Sender = Sender.UserName;

                CDO.IConfiguration iConfig = message.Configuration;

                ADODB.Fields fields = iConfig.Fields;

                fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2;

                fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = mailFrom;

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

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

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

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

                fields.Update();

                message.Send();

                message = null;

                return 0;

            }
            catch (Exception ex)
            {
                return -1;
            }
        }
Esempio n. 3
1
        /// <summary>
        /// 发送EMAIL
        /// </summary>
        /// <param name="message">MailMessage</param>
        /// <param name="smtp">SmtpClient</param>
        /// <returns>true/false</returns>
        public bool Send(System.Net.Mail.MailMessage message, System.Net.Mail.SmtpClient smtp) {
            try {
                //Msg.Write("Host:{0}<br />".FormatWith(smtp.Host));
                //Msg.Write("Port:{0}<br />".FormatWith(smtp.Port));
                //Msg.Write("From:{0}<br />".FormatWith(message.From.ToJson()));
                //Msg.Write("Body:{0}<br />".FormatWith(message.Body));
                //Msg.Write("Subject:{0}<br />".FormatWith(message.Subject));
                //Msg.Write("IsBodyHtml:{0}<br />".FormatWith(message.IsBodyHtml));
                //Msg.Write("Credentials:{0}<br />".FormatWith(smtp.Credentials.GetCredential(smtp.Host, smtp.Port, "").ToJson()));
                //Msg.Write("To:{0}<br />".FormatWith(message.To.ToJson()));
                //Msg.Write("Cc:{0}<br />".FormatWith(message.CC.ToJson()));
                StringBuilder toList = new StringBuilder();
                message.To.Do(p => toList.Append(p.Address).Append(";"));
                StringBuilder ccList = new StringBuilder();
                message.CC.Do(p => ccList.Append(p.Address).Append(";"));

                CDO.Message objMail = new CDO.Message();
                objMail.To = toList.ToStr();
                objMail.CC = ccList.ToStr();
                objMail.From = "\"{0}\"<{1}>".FormatWith(message.From.DisplayName, message.From.Address);
                objMail.Subject = message.Subject;
                if (message.IsBodyHtml) objMail.HTMLBody = message.Body; else objMail.TextBody = message.Body;
                objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = smtp.Port; //设置端口
                objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = smtp.Host;
                objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2;
                objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"].Value = 10;
                if (!smtp.UseDefaultCredentials) {
                    NetworkCredential n = smtp.Credentials.GetCredential(smtp.Host, smtp.Port, "");
                    //objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = "\"{0}\"<{1}>".FormatWith(message.From.DisplayName, message.From.Address);
                    //objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress"].Value = "\"{0}\"<{1}>".FormatWith(message.From.DisplayName, message.From.Address);
                    //objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value = n.UserName;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = n.UserName;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = n.Password;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;
                } else { 
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 0;
                }
                objMail.Configuration.Fields.Update();
                objMail.Send();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(objMail);
                return true;
            } catch(Exception ex) {
                errorMessage = ex.ToExceptionDetail();
                return false;
            } finally {
                message = null;
                smtp = null;
            }
        }
Esempio n. 4
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();
        }
Esempio n. 5
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);
     }
 }
Esempio n. 6
0
 public static void SendEmailByCdo(string operation, string email, string msg)
 {
     CDO.Message objMail = new CDO.Message();
     try
     {
         objMail.To       = email;
         objMail.From     = "*****@*****.**";
         objMail.Subject  = operation;                                                                                         //邮件主题
         objMail.HTMLBody = msg;                                                                                               //邮件内容
         objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value            = 465; //设置端口
         objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value                = "smtp.163.com";
         objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value          = "*****@*****.**";
         objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress"].Value = "*****@*****.**";
         objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value           = "*****@*****.**";
         objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value              = "*****@*****.**";
         objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value              = "a2151888";
         objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value        = 2;
         objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;
         objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"].Value       = "true";//这一句指示是否使用ssl
         objMail.Configuration.Fields.Update(); objMail.Send();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     { }
     System.Runtime.InteropServices.Marshal.ReleaseComObject(objMail);
     objMail = null;
 }
Esempio n. 7
0
 ///// <summary>
 ///// 发送EMAIL
 ///// </summary>
 ///// <param name="toEmail">EMAIL</param>
 ///// <returns>是否成功</returns>
 //public bool Send2(string toEmail) {
 //    ISmtpMail ESM = new SmtpMail();
 //    try {
 //        //ESM.RecipientName = toEmail;
 //        ESM.AddRecipient(new string[] { toEmail });
 //        ESM.MailDomainPort = 25;
 //        ESM.Html = bool.Parse("true");
 //        ESM.Subject = _Subject;
 //        ESM.Body = _Body;
 //        //ESM.FromName = WebConfig.GetApp("FromEmail");
 //        ESM.From = _FromEmail;
 //        ESM.MailDomain = _SmtpServer;
 //        ESM.MailServerUserName = _SmtpUserName;
 //        ESM.MailServerPassWord = _SmtpPassword;
 //        return ESM.Send();
 //    } catch { return false; }
 //}
 /// <summary>
 /// 发送EMAIL
 /// </summary>
 /// <param name="toEmail">Email</param>
 /// <returns>是否成功</returns>
 public bool CDOMessageSend(string toEmail)
 {
     lock (lockHelper) {
         CDO.Message objMail = new CDO.Message();
         try {
             objMail.To      = toEmail;
             objMail.From    = _FromEmail;
             objMail.Subject = _Subject;
             if (_Format.Equals(System.Web.Mail.MailFormat.Html))
             {
                 objMail.HTMLBody = _Body;
             }
             else
             {
                 objMail.TextBody = _Body;
             }
             //if (!_SmtpPort.Equals("25")) objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = _SmtpPort; //设置端口
             objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value            = _SmtpServer;
             objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value             = 1;
             objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"].Value = 10;
             objMail.Configuration.Fields.Update();
             objMail.Send();
             return(true);
         } catch {} finally{
         }
         System.Runtime.InteropServices.Marshal.ReleaseComObject(objMail);
         objMail = null;
     }
     return(false);
 }
Esempio n. 8
0
        /// <summary>
        /// 发送EMAIL
        /// </summary>
        /// <param name="message">MailMessage</param>
        /// <param name="smtp">SmtpClient</param>
        /// <returns>true/false</returns>
        public bool Send(System.Net.Mail.MailMessage message, System.Net.Mail.SmtpClient smtp)
        {
            try {
                //Msg.Write("Host:{0}<br />".FormatWith(smtp.Host));
                //Msg.Write("Port:{0}<br />".FormatWith(smtp.Port));
                //Msg.Write("From:{0}<br />".FormatWith(message.From.ToJson()));
                //Msg.Write("Body:{0}<br />".FormatWith(message.Body));
                //Msg.Write("Subject:{0}<br />".FormatWith(message.Subject));
                //Msg.Write("IsBodyHtml:{0}<br />".FormatWith(message.IsBodyHtml));
                //Msg.Write("Credentials:{0}<br />".FormatWith(smtp.Credentials.GetCredential(smtp.Host, smtp.Port, "").ToJson()));
                //Msg.Write("To:{0}<br />".FormatWith(message.To.ToJson()));
                //Msg.Write("Cc:{0}<br />".FormatWith(message.CC.ToJson()));
                StringBuilder toList = new StringBuilder();
                message.To.Do(p => toList.Append(p.Address).Append(";"));
                StringBuilder ccList = new StringBuilder();
                message.CC.Do(p => ccList.Append(p.Address).Append(";"));

                CDO.Message objMail = new CDO.Message();
                objMail.To      = toList.ToStr();
                objMail.CC      = ccList.ToStr();
                objMail.From    = "\"{0}\"<{1}>".FormatWith(message.From.DisplayName, message.From.Address);
                objMail.Subject = message.Subject;
                if (message.IsBodyHtml)
                {
                    objMail.HTMLBody = message.Body;
                }
                else
                {
                    objMail.TextBody = message.Body;
                }
                objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value        = smtp.Port; //设置端口
                objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value            = smtp.Host;
                objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value             = 2;
                objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"].Value = 10;
                if (!smtp.UseDefaultCredentials)
                {
                    NetworkCredential n = smtp.Credentials.GetCredential(smtp.Host, smtp.Port, "");
                    //objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = "\"{0}\"<{1}>".FormatWith(message.From.DisplayName, message.From.Address);
                    //objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress"].Value = "\"{0}\"<{1}>".FormatWith(message.From.DisplayName, message.From.Address);
                    //objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value = n.UserName;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value     = n.UserName;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value     = n.Password;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;
                }
                else
                {
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 0;
                }
                objMail.Configuration.Fields.Update();
                objMail.Send();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(objMail);
                return(true);
            } catch (Exception ex) {
                errorMessage = ex.ToExceptionDetail();
                return(false);
            } finally {
                message = null;
                smtp    = null;
            }
        }
        public void CDOEXSendEmail(String recipient)
        {
            CDO.Message objMessage = new CDO.Message();

            objMessage.From     = "*****@*****.**";
            objMessage.To       = recipient;
            objMessage.Subject  = "Testing some CDOEX functionality";
            objMessage.TextBody = "Yup, it seems to be working ok!\r\n\r\nCheers,\r\nMikael";
            objMessage.Send();
        }
        public AlertSendStatus Send()
        {
            AlertSendStatus alertSendStatus = new AlertSendStatus {
                IsSend          = false,
                ProviderMessage = "Waiting"
            };

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

                iConfg = oMsg.Configuration;

                ADODB.Fields oFields;
                oFields = iConfg.Fields;

                // Set configuration.
                oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value             = 2;
                oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value            = "smtp.gmail.com";
                oFields["http://schemas.microsoft.com/cdo/configuration/smptserverport"].Value        = 587;
                oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value      = 1;
                oFields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"].Value            = true;
                oFields["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"].Value = 60;
                oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value          = "*****@*****.**";
                oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value          = "drone123";

                oFields.Update();

                oMsg.CreateMHTMLBody(emailMessage.EmailURL);
                oMsg.Subject = emailMessage.EmailSubject;

                //TODO: Change the To and From address to reflect your information.
                oMsg.From = "Exponent <*****@*****.**>";
                oMsg.To   = emailMessage.ToAddress;

                //ADD attachment.
                //TODO: Change the path to the file that you want to attach.
                if (!String.IsNullOrEmpty(emailMessage.Attachments))
                {
                    foreach (String FileWithPath in emailMessage.Attachments.Split(','))
                    {
                        oMsg.AddAttachment(FileWithPath);
                    }
                }

                oMsg.Send();
                alertSendStatus.IsSend          = true;
                alertSendStatus.ProviderMessage = "Send Successfully";
            } catch (Exception e) {
                alertSendStatus.ProviderMessage = e.Message;
            }

            return(alertSendStatus);
        }
Esempio n. 11
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            dynamic objMail = new CDO.Message();

            try
            {
                if (txtValidation.Text == "30")
                {
                    dynamic      fromAddress  = "*****@*****.**";
                    const string fromPassword = "******";
                    dynamic      toAddress    = "*****@*****.**";
                    string       subject      = "Test";
                    dynamic      EnableSsl    = true;
                    dynamic      smtpServer   = "smtp.exmail.qq.com";
                    dynamic      smtpPort     = "465";
                    string       body         = "" + "\r\n";
                    body += "------------------------------------TrustPLus Main Page Email------------------------------------" + "\r\n";
                    body += "Customer Name: " + txtName.Text + "\r\n";
                    body += "Customer Cell: " + txtPhoneNumber.Text + "\r\n";
                    body += "Customer Email: " + txtEmail.Text + "\r\n";
                    body += "Title: " + "正信网站客户信息" + "\r\n";
                    body += "---------" + "\r\n";
                    body += "Message: " + txtEmailMessage.Text;
                    //here on button click what will done
                    //SendMail()
                    objMail.To      = toAddress;
                    objMail.From    = fromAddress;
                    objMail.Subject = subject;
                    //objMail.HTMLBody = body
                    objMail.TextBody = body;
                    objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport").Value            = smtpPort;
                    objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value                = smtpServer;
                    objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendemailaddress").Value          = fromAddress;
                    objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress").Value = toAddress;
                    //objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpaccountname").Value = fromAddress
                    objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername").Value     = fromAddress;
                    objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword").Value     = fromPassword;
                    objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value        = 2;
                    objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").Value = 1;
                    objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl").Value       = EnableSsl;
                    objMail.Configuration.Fields.Update();
                    objMail.Send();
                }
                else
                {
                    txtEmail.Focus();
                }
            }
            catch (Exception)
            {
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(objMail);
        }
Esempio n. 12
0
        public bool Receive(ISmtpMessage message)
        {
            CDOSmtpMessage cdoSmtpMessage = message as CDOSmtpMessage;

            CDO.Message cdoMessage = null;
            if (cdoSmtpMessage != null)
            {
                cdoMessage = cdoSmtpMessage.InnerMessage;
            }
            if (cdoMessage == null)
            {
                cdoMessage = Extensions.LoadCDOMessageFromText(message.GetMessageText());
            }

            cdoMessage.Send(this.Settings.Server, this.Settings.Port);
            return(true);
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var myMail = new CDO.Message();

            myMail.Subject  = "Sending email with CDO";
            myMail.From     = "*****@*****.**";
            myMail.To       = "*****@*****.**";
            myMail.HTMLBody = "<h1>This is a message.</h1>";

            myMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value      = 2;
            myMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value     = "localhost";
            myMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = 25;
            myMail.Configuration.Fields.Update();
            myMail.Send();
            myMail = null;
        }
Esempio n. 14
0
        public IActionResult Index()
        {
            var myMail = new CDO.Message();

            myMail.Subject  = "Sending email with CDO";
            myMail.From     = "*****@*****.**";
            myMail.To       = "*****@*****.**";
            myMail.HTMLBody = "<h1>This is a message.</h1>";

            myMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value      = 2;
            myMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value     = "localhost";
            myMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = 25;
            myMail.Configuration.Fields.Update();
            myMail.Send();
            myMail = null;
            return(View());
        }
Esempio n. 15
0
        /// <summary>
        /// 发送
        /// </summary>
        /// <param name="To">收件人</param>
        /// <param name="HTMLBody">邮件正文</param>
        public static void Send(string To, string HTMLBody)
        {
            //需要两个DLL
            //Interop.ADODB.dll
            //Interop.CDO.dll
            string From      = "*****@*****.**";
            string Subject   = "欢迎进入终生领导艺术学院学习";
            string UsersName = "*****@*****.**";
            string Password  = "******";
            string SMTP      = "mail.situational.com.cn";

            try
            {
                CDO.Message Msg = new CDO.Message();
                Msg.From     = From;
                Msg.To       = To;
                Msg.Subject  = Subject;
                Msg.HTMLBody = HTMLBody;

                //附件
                //Msg.AddAttachment(@"C:\Users\Administrator\Desktop\20081022(008).rar", "", "");

                //Msg.HTMLBody = HttpContent("http://www.situational.com.cn/LearningInformation/Details61.shtml");
                CDO.IConfiguration Config  = Msg.Configuration;
                ADODB.Fields       oFields = Config.Fields;
                oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value        = 2;
                oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value     = UsersName;
                oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value     = Password;
                oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;
                oFields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value     = 0x0804;
                oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value       = SMTP;
                oFields.Update();

                Msg.BodyPart.Charset     = "gb2312";
                Msg.HTMLBodyPart.Charset = "gb2312";

                Msg.Send();
                Msg = null;
            }
            catch
            { }
        }
Esempio n. 16
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;
            }
        }
Esempio n. 17
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);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// CDOMessageSend
        /// </summary>
        /// <param name="toEmail"></param>
        /// <param name="sendusing"></param>
        /// <returns></returns>
        public bool CDOMessageSend(string toEmail, int sendusing)
        {
            lock (lockHelper) {
                CDO.Message objMail = new CDO.Message();
                try {
                    objMail.To      = toEmail;
                    objMail.From    = _FromEmail;
                    objMail.Subject = _Subject;
                    if (_Format.Equals(System.Web.Mail.MailFormat.Html))
                    {
                        objMail.HTMLBody = _Body;
                    }
                    else
                    {
                        objMail.TextBody = _Body;
                    }
                    if (!_SmtpPort.Equals("25"))
                    {
                        objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = _SmtpPort;                          //设置端口
                    }
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value                = _SmtpServer;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value                 = sendusing;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value          = _FromEmail;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress"].Value = _FromEmail;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value           = _SmtpUserName;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value              = _SmtpUserName;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value              = _SmtpPassword;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value          = 1;

                    objMail.Configuration.Fields.Update();
                    objMail.Send();
                    return(true);
                } catch { } finally{
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(objMail);
                objMail = null;
            }
            return(false);
        }
Esempio n. 19
0
        /// <summary>
        /// Sends mail using the Mail message object
        /// </summary>
        /// <param name="IsBodyHtml"></param>
        /// <returns></returns>
        public bool SendMail()
        {
            try
            {
                //use CDO to send if the hostingplace is "HP"
                if (ConfigUtil.HostingPlace.ToLower() == "hp")
                {
                    CDO.Message oMsg;

                    ////CDO.IBodyPart iBp;

                    // Create a new message.
                    oMsg = new CDO.Message();
                    //oMsg.From = "*****@*****.**";
                    //oMsg.To = "*****@*****.**";

                    CDO.IConfiguration iConfg;
                    iConfg = oMsg.Configuration;

                    ADODB.Fields oFields = iConfg.Fields;

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

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

                    oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = "mailhost.prod";

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


                    oMsg.Configuration.Fields.Update();


                    oMsg.From    = MailMessageObject.From.Address;
                    oMsg.To      = string.Join(",", new List <string>(from e in MailMessageObject.To select e.Address).ToArray());
                    oMsg.CC      = string.Join(",", new List <string>(from e in MailMessageObject.CC select e.Address).ToArray());
                    oMsg.BCC     = string.Join(",", new List <string>(from e in MailMessageObject.Bcc select e.Address).ToArray());
                    oMsg.Subject = MailMessageObject.Subject;
                    //oMsg.TextBody = MailMessageObject.Body;
                    oMsg.HTMLBody = MailMessageObject.Body;


                    // Send mail.

                    oMsg.Send();


                    oMsg = null;

                    return(true);
                }
                else
                {
                    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(ConfigUtil.EmailServer);

                    if (ConfigUtil.EmailServerRequiresAuthentication == true)
                    {
                        System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential(ConfigUtil.EmailServerUserName, ConfigUtil.EmailServerPassword);
                        smtp.UseDefaultCredentials = false;
                        smtp.Credentials           = basicAuthenticationInfo;
                        smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
                    }


                    ApplyBusinessRules();
                    smtp.Send(this.MailMessageObject);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                //TODO : Logout

                return(false);
            }
        }
Esempio n. 20
0
    private void sendMail1(string mailTo, string strToName, string mailCC, string mailBCC, string strTitle, string strBody, string strFilesPath)
    {
        CDO.Message msg      = new CDO.Message();
        string      passWord = "******";
        string      from     = "*****@*****.**";
        //string from = "hyitech\\caservice";
        string server = "192.168.10.32";// "192.168.10.32";

        //发件人
        msg.From = from;
        //收件人
        msg.To = mailTo;
        //抄送
        if (mailCC.Trim().Length > 0)
        {
            msg.CC = mailCC;
        }
        //密送
        if (mailBCC.Trim().Length > 0)
        {
            msg.BCC = mailBCC;
        }
        //标题
        msg.Subject = strTitle;
        //正文
        msg.TextBody = strBody;

        if (strFilesPath.Trim().Length > 0)
        {
            msg.AddAttachment(strFilesPath);
        }
        CDO.IConfiguration iConfig = msg.Configuration;
        ADODB.Fields       fields  = iConfig.Fields;

        //fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2;
        //fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = server;
        //fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = 25;
        //fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;
        ////fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = true;
        //fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = "*****@*****.**";
        //fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = passWord;

        fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value        = 2;
        fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = "*****@*****.**"; //修改这里,并保持发件人与这里的地址一致
        fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value  = "*****@*****.**"; //修改这里
        fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value     = "caservice";             //修改这里
        fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value     = "123.com";               //修改这里
        fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;
        //value=0 代表Anonymous验证方式(不需要验证)
        //value=1 代表Basic验证方式(使用basic (clear-text) authentication.
        //The configuration sendusername/sendpassword or postusername/postpassword fields are used to specify credentials.)
        //Value=2 代表NTLM验证方式(Secure Password Authentication in Microsoft Outlook Express)
        fields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value = 0x0804;
        fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value   = "192.168.10.32";

        fields.Update();
        try
        {
            msg.Send();
            msg = null;
            Response.Write(strTitle + "发送完成<br />");
        }
        catch (Exception ex)
        {
            WebLog.WriteLog(ex.Message + ex.InnerException + ex.HelpLink + ex.Data + ex.Source + ex.StackTrace + ex.TargetSite, "sendMail");
        }
    }
Esempio n. 21
0
        /// <summary>
        /// Sends mail using the Mail message object
        /// </summary>
        /// <param name="IsBodyHtml"></param>
        /// <returns></returns>
        public bool SendMailCDO()
        {
            try
            {
                //use CDO to send if the hostingplace is "HP"


                CDO.Message oMsg;

                ////CDO.IBodyPart iBp;

                // Create a new message.
                oMsg = new CDO.Message();
                //oMsg.From = "*****@*****.**";
                //oMsg.To = "*****@*****.**";

                CDO.IConfiguration iConfg;
                iConfg = oMsg.Configuration;

                ADODB.Fields oFields = iConfg.Fields;

                oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = ConfigUtil.SmtpSendUsing;

                oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = ConfigUtil.SmtpHost;

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

                oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = ConfigUtil.SmtpCredentialsUid;

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

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

                oFields["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"].Value = ConfigUtil.SmtpConnectionTimeout;


                oMsg.Configuration.Fields.Update();


                oMsg.From    = MailMessageObject.From.Address;
                oMsg.To      = string.Join(",", new List <string>(from e in MailMessageObject.To select e.Address).ToArray());
                oMsg.CC      = string.Join(",", new List <string>(from e in MailMessageObject.CC select e.Address).ToArray());
                oMsg.BCC     = string.Join(",", new List <string>(from e in MailMessageObject.Bcc select e.Address).ToArray());
                oMsg.Subject = MailMessageObject.Subject;
                //oMsg.TextBody = MailMessageObject.Body;
                oMsg.HTMLBody = MailMessageObject.Body;


                // Send mail.

                oMsg.Send();


                oMsg = null;

                return(true);
            }

            catch (Exception ex)
            {
                //TODO : Logout

                return(false);
            }
        }
        /// <summary>
        /// Sends the email MHTML.
        /// </summary>
        /// <param name="message">The message.</param>
        public virtual void SendMhtml(MailMessage message)
        {
            lock (_lock)
                try
                {
                    var m = new CDO.Message();

                    // set message
                    var s = new ADODB.Stream();
                    s.Charset = "ascii";
                    s.Open();
                    s.WriteText(message.Body);
                    m.DataSource.OpenObject(s, "_Stream");

                    // set configuration
                    var f = m.Configuration.Fields;
                    switch (DeliveryMethod)
                    {
                    case SmtpDeliveryMethod.Network:
                        f["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value  = CDO.CdoSendUsing.cdoSendUsingPort;
                        f["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = Host;
                        break;

                    case SmtpDeliveryMethod.SpecifiedPickupDirectory:
                        f["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CDO.CdoSendUsing.cdoSendUsingPickup;
                        f["http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"].Value = PickupDirectoryLocation;
                        break;

                    default: throw new NotSupportedException();
                    }
                    f.Update();

                    // set other values
                    m.MimeFormatted = true;
                    m.Subject       = message.Subject;
                    if (message.From != null)
                    {
                        m.From = message.From.ToString();
                    }
                    var to = (message.To != null ? string.Join(",", message.To.Select(x => x.ToString()).ToArray()) : null);
                    if (!string.IsNullOrEmpty(to))
                    {
                        m.To = to;
                    }
                    var bcc = (message.Bcc != null ? string.Join(",", message.Bcc.Select(x => x.ToString()).ToArray()) : null);
                    if (!string.IsNullOrEmpty(to))
                    {
                        m.BCC = bcc;
                    }
                    var cc = (message.CC != null ? string.Join(",", message.CC.Select(x => x.ToString()).ToArray()) : null);
                    if (!string.IsNullOrEmpty(to))
                    {
                        m.CC = cc;
                    }
                    if (message.Attachments != null)
                    {
                        foreach (var attachment in message.Attachments.Where(x => x != null))
                        {
                            AddAttachement(m, attachment, false);
                        }
                    }
                    m.Send();
                }
                catch (Exception ex) { throw ex; }
        }
Esempio n. 23
0
        /// <summary>
        /// Sends the email MHTML.
        /// </summary>
        /// <param name="message">The message.</param>
        public virtual void SendMhtml(MailMessage message)
        {
            lock (_lock)
                try
                {
                    var m = new CDO.Message();

                    // set message
                    var s = new ADODB.Stream();
                    s.Charset = "ascii";
                    s.Open();
                    s.WriteText(message.Body);
                    m.DataSource.OpenObject(s, "_Stream");

                    // set configuration
                    var f = m.Configuration.Fields;
                    switch (DeliveryMethod)
                    {
                        case SmtpDeliveryMethod.Network:
                            f["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CDO.CdoSendUsing.cdoSendUsingPort;
                            f["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = Host;
                            break;
                        case SmtpDeliveryMethod.SpecifiedPickupDirectory:
                            f["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CDO.CdoSendUsing.cdoSendUsingPickup;
                            f["http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"].Value = PickupDirectoryLocation;
                            break;
                        default: throw new NotSupportedException();
                    }
                    f.Update();

                    // set other values
                    m.MimeFormatted = true;
                    m.Subject = message.Subject;
                    if (message.From != null) m.From = message.From.ToString();
                    var to = (message.To != null ? string.Join(",", message.To.Select(x => x.ToString()).ToArray()) : null);
                    if (!string.IsNullOrEmpty(to)) m.To = to;
                    var bcc = (message.Bcc != null ? string.Join(",", message.Bcc.Select(x => x.ToString()).ToArray()) : null);
                    if (!string.IsNullOrEmpty(to)) m.BCC = bcc;
                    var cc = (message.CC != null ? string.Join(",", message.CC.Select(x => x.ToString()).ToArray()) : null);
                    if (!string.IsNullOrEmpty(to)) m.CC = cc;
                    if (message.Attachments != null)
                        foreach (var attachment in message.Attachments.Where(x => x != null))
                            AddAttachement(m, attachment, false);
                    m.Send();
                }
                catch (Exception ex) { throw ex; }
        }
Esempio n. 24
0
        /// <summary>
        /// Sends the email or SMS.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="textBody">The text body.</param>
        /// <param name="useMailOrSms">if set to <c>true</c> [use email or SMS].</param>
        /// <param name="isAutomaticMail">if set to <c>true</c> [is automatic mail].</param>
        /// <param name="attachmentFilePath">The attachment file path.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        public static bool SendEmail(string address, string subject, string textBody, bool useMailOrSms, bool isAutomaticMail, string attachmentFilePath = null)
        {
            bool useMail = Settings.Default.UseMail;
            if (!useMail || !useMailOrSms || String.IsNullOrEmpty(address))
                return false;

            try
            {
                var message = new CDO.Message();
                message.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value =
                    SmtpServer;
                message.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value =
                    SmtpServerPort;
                message.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value =
                    SendUsing;
                message.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value =
                    SmtpAuthenticate;
                message.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value =
                    SendUserName;
                message.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value =
                    SendPassword;
                message.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"].Value =
                    SmtpUseSsl;
                message.Configuration.Fields.Update();

                message.From = SendUserName;
                message.To = address;
                message.Subject = String.Format("{0}{1}", Settings.Default.EmailPrefix, subject);
                message.BodyPart.Charset = "UTF-8";

                Encoding defaultEncoding = Encoding.Default;
                Encoding utf8 = Encoding.UTF8;
                string wholeTextBody = isAutomaticMail
                                           ? String.Format(MailResource.Mail_AutomaticMailTextBodyTemplate, textBody)
                                           : textBody;
                byte[] defaultBytes = defaultEncoding.GetBytes(wholeTextBody);
                byte[] uftBytes = Encoding.Convert(defaultEncoding, utf8, defaultBytes);
                var utfChars = new char[utf8.GetCharCount(uftBytes, 0, uftBytes.Length)];
                utf8.GetChars(uftBytes, 0, uftBytes.Length, utfChars, 0);
                var text = new string(utfChars);
                message.TextBody = text;

                if (!String.IsNullOrEmpty(attachmentFilePath))
                {
                    message.AddAttachment(attachmentFilePath);
                }

                message.Send();
                ReleaseComObject(message);
            }
            catch (Exception e)
            {
                var logParameter = new Logger.LogParameter {AdditionalMessage = String.Format("address: {0}", address)};
                Logger.SetLog(e, logParameter);
                return false;
            }

            return true;
        }
Esempio n. 25
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);
        }
Esempio n. 26
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;
            }
        }
Esempio n. 27
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);
        }
Esempio n. 28
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);
            //}
        }
Esempio n. 29
0
        /// <summary>
        ///Updated Method,Send Mail with CDO method
        /// </summary>
        /// <param name="stage"></param>
        /// <param name="zipAttch"></param>
        /// <param name="reportFileName"></param>
        public static void EmailNotification(string stage, bool zipAttch, string reportFileName = null)
        {
            if (ValidateEmail() == false) return;

            Console.WriteLine(ConsoleMessages.MSG_DASHED);
            Console.WriteLine("Sending Email ....!!!");
            Console.WriteLine(ConsoleMessages.MSG_DASHED);

            try
            {
                string[] emailStr = null;
                switch (stage.ToLower())
                {

                    case "start":
                        emailStr = EmailTemplate(Property.EmailStartTemplate);
                        break;
                    case "end":
                        emailStr = EmailTemplate(Property.EmailEndTemplate);
                        break;
                }

                #region Email Configuration settings

                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 = GetParameter("EmailSMTPServer").Trim();

                field = fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
                field.Value = int.Parse(GetParameter("EmailSMTPPort").Trim());

                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 = GetParameter("EmailSMTPUsername").Trim();

                field = fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"];
                field.Value = GetParameter("EmailSMTPPassword").Trim();

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

                #endregion

                #region  Add attachments

                if (stage == "end")
                {
                    // Create  the file attachment for this e-mail message.
                    string file = Property.HtmlFileLocation + "/" + Property.ReportZipFileName;
                    if (File.Exists(file) && zipAttch)
                    {
                        message.AddAttachment(file);

                    }
                    else if (!zipAttch)
                    {
                        string htmlFile;
                        if (string.IsNullOrWhiteSpace(reportFileName))
                        {
                            htmlFile = Property.HtmlFileLocation + "/HtmlReportMail.html";
                        }
                        else
                        {
                            htmlFile = reportFileName;
                        }
                        message.AddAttachment(htmlFile);
                    }

                }

                #endregion

                if (!string.IsNullOrEmpty(Property.ReportSummaryBody))
                {
                    message.HTMLBody = Property.ReportSummaryBody;

                }
                else
                {
                    if (emailStr != null)
                    {
                        string mailTextBody = GetEmailTextBody(emailStr[3], stage);
                        message.TextBody = mailTextBody;
                    }
                }
                message.From = "KryptonAutomation";
                message.Sender = GetParameter("EmailSMTPUsername").Trim();
                message.To = GetRecipientList();
                if (emailStr != null) message.Subject = GetEmailSubjectMessage(emailStr[1]);
                message.Send();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to send email notificiation. Error: " + ex.Message + "\n" +
                                  "Please make sure you have smtp service installed and running");

            }
        }
Esempio n. 30
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);
        }
Esempio n. 31
0
        /// <summary>
        /// CDOMessageSend
        /// </summary>
        /// <param name="toEmail"></param>
        /// <param name="sendusing"></param>
        /// <returns></returns>
        public bool CDOMessageSend(string toEmail,int sendusing) {
            lock (lockHelper) {
                CDO.Message objMail = new CDO.Message();
                try {
                    objMail.To = toEmail;
		            objMail.From = _FromEmail;
		            objMail.Subject = _Subject;
		            if (_Format.Equals(System.Web.Mail.MailFormat.Html)) objMail.HTMLBody = _Body; else objMail.TextBody = _Body;
                    if (!_SmtpPort.Equals("25")) objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = _SmtpPort; //设置端口
		            objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = _SmtpServer;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = sendusing;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = _FromEmail;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress"].Value = _FromEmail;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value = _SmtpUserName;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = _SmtpUserName;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = _SmtpPassword;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value=1;    

		            objMail.Configuration.Fields.Update();
		            objMail.Send();
                    return true;
                } catch { } finally{
                    
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(objMail);
                objMail = null;
            }
            return false;
        }