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. 2
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. 3
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. 4
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. 5
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");

            }
        }