상속: System.Configuration.ConfigurationSection
예제 #1
0
 internal SmtpSectionInternal(SmtpSection section)
 {
     this.deliveryMethod           = section.DeliveryMethod;
     this.from                     = section.From;
     this.network                  = new SmtpNetworkElementInternal(section.Network);
     this.specifiedPickupDirectory = new SmtpSpecifiedPickupDirectoryElementInternal(section.SpecifiedPickupDirectory);
 }
예제 #2
0
        /// <summary>
        /// Save email config settings
        /// </summary>
        /// <param name="collection">Collection of config settings</param>
        /// <returns>listing of config settings</returns>
        public ActionResult SaveEmail(FormCollection collection)
        {
            if (collection != null)
            {
                string emailLogon = collection["emailLogon"];
                string emailPassword = collection["emailPassword"];
                string host = collection["host"];
                string portString = collection["port"];
                int port;

                FeedConfiguration mailSettingsConfig = new FeedConfiguration(this.HttpContext);

                SmtpSection smtpSection = new SmtpSection();

                smtpSection.Network.UserName = emailLogon;
                smtpSection.Network.Password = emailPassword;
                smtpSection.Network.Host = host;

                if (int.TryParse(portString, out port) == true)
                {
                    smtpSection.Network.Port = port;
                }

                this.FeedConfiguration.SmtpSection = smtpSection;
            }

            return this.Index();
        }
예제 #3
0
    protected void imgSubmit_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("http://www.greymediahouse.com/#contact");

        try
        {
            var smtp = new System.Net.Mail.SmtpClient();
            var credential = new System.Net.Configuration.SmtpSection().Network;

            string strHost = smtp.Host;
            int port = smtp.Port;
            string strUserName = credential.UserName;
            string strFromPass = credential.Password;

            string strtoAddress = ConfigurationManager.AppSettings["EnquiryToMail"];
            string strfromAddress = ConfigurationManager.AppSettings["EnquiryFromMail"];
            string strSubject = txtSubject.Text.ToString();
            string strbody = "<html><head></head><body>Name : " + txtName.Text.ToString() + "<br/>Email : "
                + txtEmail.Text.ToString() + "<br/>Description : " + txtDescription.Text.ToString() + "</body></html";

            objCommon.SendEMail(strtoAddress, strfromAddress, strSubject, strbody, null, null, null);
        }
        catch (Exception ex)
        {
            objCommon.LogFile(ex.Message, "imgSubmit_Click", ex);
        }
    }
예제 #4
0
        /// <summary>
        /// Creates the mail message
        /// </summary>
        /// <param name="toEmail"></param>
        /// <param name="quoteRequest"></param>
        /// <param name="smtpConfig"></param>
        /// <returns></returns>
        private MailMessage CreateMailMessage(QuoteRequest quoteRequest, SmtpSection smtpConfig)
        {
            MailMessage message = new MailMessage(smtpConfig.From, quoteRequest.Contact.Email);
            message.Subject = GetEmailSubject(quoteRequest);
            message.Body = quoteRequest.Message;

            return message;
        }
예제 #5
0
        /// <summary>
        /// Creates the SMTP client
        /// </summary>
        /// <returns></returns>
        private SmtpClient CreateSmtpClient(SmtpSection smtpConfig)
        {
            SmtpClient smtp = new SmtpClient
            {
                Host = smtpConfig.Network.Host,
                Port = smtpConfig.Network.Port
            };

            return smtp;
        }
예제 #6
0
 internal static SmtpSectionInternal GetSection()
 {
     lock (ClassSyncObject)
     {
         SmtpSection section = System.Configuration.PrivilegedConfigurationManager.GetSection(ConfigurationStrings.SmtpSectionPath) as SmtpSection;
         if (section == null)
         {
             return(null);
         }
         return(new SmtpSectionInternal(section));
     }
 }
예제 #7
0
        public static void SendEmail(string to, string subject, string body)
        {
            System.Net.Configuration.SmtpSection smtp = new System.Net.Configuration.SmtpSection();
            var section = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;

            //Aunque lo marca como obsoleto, no funciona bien la alternativa (System.Net.Mail.MailMessage), en ese caso da el siguiente error:
            //El servidor ha cometido una infracción de protocolo La respuesta del servidor fue: UGFzc3dvcmQ6
            //Más info: https://tutel.me/c/programming/questions/35148760/c+smtp+authentication+failed+but+credentials+are+correct
            System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
            msg.Body = body;

            string smtpServer       = section.Network.Host;
            string userName         = section.Network.UserName;
            string password         = section.Network.Password;
            int    cdoBasic         = 1;
            int    cdoSendUsingPort = 2;

            if (userName.Length > 0)
            {
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", smtpServer);
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", section.Network.Port);
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", cdoSendUsingPort);
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", cdoBasic);
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName);
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
            }
            msg.To              = to;
            msg.From            = section.From;
            msg.Subject         = subject;
            msg.BodyFormat      = MailFormat.Html;//System.Text.Encoding.UTF8;
            SmtpMail.SmtpServer = smtpServer;

            try
            {
                SmtpMail.Send(msg);
            }
            catch (Exception ex)
            {
                Logger logger = NLoggerManager.Instance;
                logger.Error("Error al enviar correo. Error: " + ex.Message + " " + ex.InnerException);
                Notificaciones.NotifySystemOps(ex);
                throw ex;//devolvemos la excepción para controlar que no se ha enviado y que la pagina origen lo tenga en cuenta
            }
        }
 static EmailProvider()
 {
     Smtp = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
 }
 static EmailUtils()
 {
     cfg = ConfigurationManager.GetSection(@"system.net/mailSettings/smtp") as SmtpSection;
     smtElement = cfg.Network;
 }
예제 #10
0
        internal SmtpSectionInternal(SmtpSection section)
        {
            this.deliveryMethod = section.DeliveryMethod;
            this.from = section.From;

            this.network = new SmtpNetworkElementInternal(section.Network);
            this.specifiedPickupDirectory = new SmtpSpecifiedPickupDirectoryElementInternal(section.SpecifiedPickupDirectory);
        }
예제 #11
0
        public void MailDeliveryMethod_ReturnsValue_FromConfig(SmtpDeliveryMethod deliveryMethod)
        {
            var mockConfigReader = new Mock<IReadConfiguration>(MockBehavior.Strict);
            var smtpSection = new SmtpSection
            {
                DeliveryMethod = deliveryMethod,
            };
            mockConfigReader.Setup(x => x.GetSection("system.net/mailSettings/smtp")).Returns(smtpSection);
            var appConfiguration = new AppConfiguration(mockConfigReader.Object);

            SmtpDeliveryMethod result = appConfiguration.MailDeliveryMethod;
            result.ShouldEqual(deliveryMethod);
        }
예제 #12
0
        //public static SmtpSection Config
        //{
        //    get
        //    {
        //        if (_config == null)
        //        {
        //            _config = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;

        //        }
        //        return _config;
        //    }
        //}

        public EmailSender(SmtpSection config)
        {
            _config = config;
        }
예제 #13
0
        private bool SendNetworkMail(SmtpSection mailSetting, string strTo, string strSubject, string strBody)
        {
            using (var smtpClient = new SmtpClient())
            {
                smtpClient.EnableSsl = mailSetting.Network.EnableSsl;
                smtpClient.Host = mailSetting.Network.Host;
                smtpClient.Port = mailSetting.Network.Port;
                smtpClient.UseDefaultCredentials = mailSetting.Network.DefaultCredentials;
                smtpClient.DeliveryMethod = mailSetting.DeliveryMethod;
                smtpClient.Credentials = new NetworkCredential(mailSetting.Network.UserName,
                    mailSetting.Network.Password);

                using (var mailMessage = new MailMessage(mailSetting.From, strTo, strSubject, strBody))
                {
                    smtpClient.Send(mailMessage);
                }
            }
            return true;
        }
예제 #14
0
        private bool SendSpecifiedPickupMail(SmtpSection mailSetting, string strTo, string strSubject, string strBody)
        {
            using (var smtpClient = new SmtpClient())
            {
                smtpClient.DeliveryMethod = mailSetting.DeliveryMethod;
                smtpClient.PickupDirectoryLocation = _fileService.GetDirectoryFolderLocation(DirectoryFolders.Jt76Email);
                mailSetting.From = mailSetting.From;

                using (var mailMessage = new MailMessage(mailSetting.From, strTo, strSubject, strBody))
                {
                    smtpClient.Send(mailMessage);
                }
            }
            return true;
        }
예제 #15
0
 public EmailHelper()
 {
     smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
 }