当前位置: 首页>>代码示例>>C#>>正文


C# Mail.SmtpClient类代码示例

本文整理汇总了C#中System.Net.Mail.SmtpClient的典型用法代码示例。如果您正苦于以下问题:C# System.Net.Mail.SmtpClient类的具体用法?C# System.Net.Mail.SmtpClient怎么用?C# System.Net.Mail.SmtpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


System.Net.Mail.SmtpClient类属于命名空间,在下文中一共展示了System.Net.Mail.SmtpClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendSenha

        public static bool SendSenha(string from, string to, string subject, string mensagem)
        {
            System.Net.Mail.SmtpClient s = null;
            try
            {
                s = new System.Net.Mail.SmtpClient("smtp.live.com", 587);
                s.EnableSsl = true;
                s.UseDefaultCredentials = false;
                s.Credentials = new System.Net.NetworkCredential("[email protected]", "Projeto032015");
                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(
                    new System.Net.Mail.MailAddress(from),
                    new System.Net.Mail.MailAddress(to));
                message.Body = mensagem;
                message.BodyEncoding = Encoding.UTF8;
                message.Subject = subject;
                message.SubjectEncoding = Encoding.UTF8;
                s.Send(message);
                s.Dispose();

                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                if (s != null)
                    s.Dispose();
            }
        }
开发者ID:tematek,项目名称:ProjetoMelhor,代码行数:31,代码来源:DisparaSenha.cs

示例2: Enviar

 public void Enviar(string y, string tipo, string texto)
 {
     System.Net.Mail.MailMessage correo = new System.Net.Mail.MailMessage();
     correo.From = new System.Net.Mail.MailAddress("[email protected]");
     correo.To.Add(y);
     string sub = "Tutorias compu informa";
     string tex = "Este mensaje es para informar que se tendran que   " + tipo + "\n" + texto;
     correo.Subject = sub;
     correo.Body = tex;
     correo.IsBodyHtml = false;
     correo.Priority = System.Net.Mail.MailPriority.Normal;
     //
     System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
     //
     //---------------------------------------------
     // Estos datos debes rellanarlos correctamente
     //---------------------------------------------
     smtp.Host = "smtp-mail.outlook.com";
     smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "EscuelaComputacion12");
     smtp.EnableSsl = false;
     smtp.Port = 587;
     smtp.EnableSsl = true;
     try
     {
         smtp.Send(correo);
     }
     catch (Exception ex)
     {
         var a = ex;
     }
 }
开发者ID:Eur,项目名称:Proyecto,代码行数:31,代码来源:MovilController.cs

示例3: Send

        public static void Send(string destination, string subject, string body)
        {
            var credentialUserName = "[email protected]";
            var sentFrom = "[email protected]";
            var pwd = "quiko";

            // Configure the client:
            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.riquest.de");
            client.Port = 25;
            client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;

            // Create the credentials:
            System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(credentialUserName, pwd);

            client.EnableSsl = false;
            client.Credentials = credentials;

            // Create the message:
            var mail = new System.Net.Mail.MailMessage(sentFrom, destination);

            mail.Subject = subject;
            mail.Body = body;

            // Send:
            client.Send(mail);
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:27,代码来源:EmailClient.cs

示例4: CoverDetails

        public ActionResult CoverDetails(Models.CoverDetailsModel submittedCoverDetails)
        {
            //Check if the current session has completed pre-req
            if (this.Session[cPersonalDetails] == null)
                return RedirectToAction("PersonalDetails");

            //Check if a Submission has already been done
            if (SessionIsComplete())
                return View("SubmissionCompleted");

            //Check if current Post details are valid.
            if (submittedCoverDetails != null && this.ModelState.IsValid)
            {
                var personalDetails = Session[cPersonalDetails] as Models.PersonalDetailsModel;
                var mail = CreateMail(personalDetails, submittedCoverDetails);
                using (var mc = new System.Net.Mail.SmtpClient())
                {
                    mc.Send(mail);
                }
                CompleteSession();

                return View("SubmissionCompleted");
            }
            return View(submittedCoverDetails);
        }
开发者ID:carcer,项目名称:contact,代码行数:25,代码来源:HomeController.cs

示例5: emailEvent

        } // End Sub handleLog 


        private void emailEvent() // Send email notification
        {
            try
            {
                System.Net.Mail.MailMessage notificationEmail = new System.Net.Mail.MailMessage();
                notificationEmail.Subject = "SysLog Event";
                notificationEmail.IsBodyHtml = true;

                notificationEmail.Body = "<b>SysLog Event Triggered:<br/><br/>Time: </b><br/>" +
                    System.DateTime.Now.ToString() + "<br/><b>Source IP: </b><br/>" +
                    source + "<br/><b>Event: </b><br/>" + log; // Throw in some basic HTML for readability

                notificationEmail.From = new System.Net.Mail.MailAddress("[email protected]", "SysLog Server"); // From Address
                notificationEmail.To.Add(new System.Net.Mail.MailAddress("[email protected]", "metastruct")); // To Address
                System.Net.Mail.SmtpClient emailClient = new System.Net.Mail.SmtpClient("10.10.10.10"); // Address of your SMTP server of choice

                // emailClient.UseDefaultCredentials = false; // If your SMTP server requires credentials to send email
                // emailClient.Credentials = new NetworkCredential("username", "password"); // Supply User Name and Password

                emailClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                emailClient.Send(notificationEmail); // Send the email
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.ToString());
            }

        } // End Sub emailEvent 
开发者ID:ststeiger,项目名称:SyslogClients,代码行数:31,代码来源:loghandler.cs

示例6: SendNoticeToAdmin

        public static void SendNoticeToAdmin(string subject, string content, MimeType mime) {

            UserBE adminUser = UserBL.GetAdmin(); ;

            if (adminUser == null) {
                throw new DreamAbortException(DreamMessage.InternalError(DekiResources.CANNOT_RETRIEVE_ADMIN_ACCOUNT));
            }
            
            string smtphost = string.Empty;
            int smtpport = 0;

            if (smtphost == string.Empty)
                throw new DreamAbortException(DreamMessage.Conflict(DekiResources.SMTP_SERVER_NOT_CONFIGURED));


            if (string.IsNullOrEmpty(adminUser.Email))
                throw new DreamAbortException(DreamMessage.Conflict(DekiResources.ADMIN_EMAIL_NOT_SET));

            System.Net.Mail.SmtpClient smtpclient = new System.Net.Mail.SmtpClient();
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
            msg.To.Add(adminUser.Email);
            msg.From = new System.Net.Mail.MailAddress(DekiContext.Current.User.Email, DekiContext.Current.User.Name);
            msg.Subject = DekiContext.Current.Instance.SiteName + ": " + subject;
            msg.Body = content;

            smtpclient.Host = smtphost;
            if (smtpport != 0)
                smtpclient.Port = smtpport;

            smtpclient.Send(msg);
        }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:31,代码来源:SiteBL.cs

示例7: SMTPMail

        //*****//
        //EMAIL//
        //*****//
        public void SMTPMail(string pDestino, string pAsunto, string pCuerpo)
        {
            // Crear el Mail
            using (System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage())
            {
                mail.To.Add(new System.Net.Mail.MailAddress(pDestino));
                mail.From = new System.Net.Mail.MailAddress("[email protected]");
                mail.Subject = pAsunto;
                mail.SubjectEncoding = System.Text.Encoding.UTF8;
                mail.Body = pCuerpo;
                mail.BodyEncoding = System.Text.Encoding.UTF8;
                mail.IsBodyHtml = false;

                // Agregar el Adjunto si deseamos hacerlo
                //mail.Attachments.Add(new Attachment(archivo));

                // Configuración SMTP
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);

                // Crear Credencial de Autenticacion
                smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "ReNb3270");
                smtp.EnableSsl = true;

                try
                { smtp.Send(mail); }
                catch (Exception ex)
                { throw ex; }
            } // end using mail
        }
开发者ID:richy-maximo,项目名称:Checador,代码行数:32,代码来源:Util.cs

示例8: enviarCorreoElectronico

        public static bool enviarCorreoElectronico(string pcorreoDestino, string tecnologia, string pnombreCandidato,DateTime pfechaI,DateTime pfechaF, string phora, string pcontrasenna)
        {
            System.Net.Mail.MailMessage correo = new System.Net.Mail.MailMessage();
               correo.From = new System.Net.Mail.MailAddress("[email protected]");
               correo.To.Add(pcorreoDestino);
               correo.Subject = "Prueba"+" de  "+tecnologia ;
               correo.Body = "<html><body>[email protected] " + pnombreCandidato + ", <br> Este correo es con la intención de comunicarle que la programación de la prueba de " + tecnologia + " ya puede ser accesada.<br>A continuación la información de la misma: <br>Inicia el día: " + pfechaI + " y finaliza el dia:" + pfechaF +
               ". <br>La prueba tiene que ser completada en un máximo de " + phora + " horas." +
               "<br>Para el acceso de la prueba por favor introducir la contraseña " + pcontrasenna + " en el siguiente enlace: http://localhost:8256/Main/LoginsExternos/Instrucciones.aspx </body></html>";

               correo.IsBodyHtml = true;

               System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();

               smtp.Host = "smtp.gmail.com";

               smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "diegoChing");
               smtp.EnableSsl = true;

               try
               {
               smtp.Send(correo);
               return true;
               }
               catch (Exception ex)
               {
               return false;
               throw new Exception ("Ha ocurrido un error al enviar el correo electronico ", ex);

               }
        }
开发者ID:pablobar23,项目名称:RRHH,代码行数:31,代码来源:CorreoElectronico.cs

示例9: send_mail_gmail

        public static bool send_mail_gmail(string gmail_sender_account, string gmail_sender_pass, string sender_name, string sender_email, string receiver_name, string receiver_email, string subject, string body_content)
        {
            bool flag = false;
            System.Net.NetworkCredential smtp_user_info = new System.Net.NetworkCredential(gmail_sender_account, gmail_sender_pass);

            System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
            mailMessage.From = new System.Net.Mail.MailAddress(sender_email, sender_name, System.Text.UTF8Encoding.UTF8);
            mailMessage.To.Add(new System.Net.Mail.MailAddress(receiver_email, receiver_name.Trim(), System.Text.UTF8Encoding.UTF8));
            mailMessage.Subject = subject;
            mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
            mailMessage.Body = body_content;
            mailMessage.IsBodyHtml = true;
            mailMessage.BodyEncoding = System.Text.UnicodeEncoding.UTF8;
            //mailMessage.Priority = MailPriority.High;

            /* Set the SMTP server and send the email - SMTP gmail ="smtp.gmail.com" port=587*/
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587; //port=25           
            smtp.Timeout = 100;
            smtp.EnableSsl = true;
            smtp.Credentials = smtp_user_info;

            try
            {
                smtp.Send(mailMessage);               
                flag = true;
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
            return flag;
        }        
开发者ID:jackiechou,项目名称:thegioicuaban.com,代码行数:34,代码来源:EmailClass.cs

示例10: NotificarRecuperacionContrasenia

        //private string mailFrom = "[email protected]";//ConfigurationSettings.AppSettings["MailAdmin"];
        //private string smtp = "smtp.educaria.com";//ConfigurationSettings.AppSettings["Smtp"];
        //private string smtpUserName = "[email protected]";//ConfigurationSettings.AppSettings["SmtpUserName"];
        //private string smtpPassword = "senda.portalchile";//ConfigurationSettings.AppSettings["SmtpPwd"];
        public void NotificarRecuperacionContrasenia(Usuario Usr, string Password)
        {
            try
            {

                System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
                mm.From = new System.Net.Mail.MailAddress(mailFrom);
                mm.To.Add(Usr.Email);
                mm.Subject = "CAMBIO DE CONTRASEÑA DE SENDA PORTAL";
                mm.Body = Usr.Nombres+" "+Usr.ApellidoMaterno+" "+Usr.ApellidoPaterno + ",\r La contraseña de acceso a Senda Portal se generó con éxito. \r\rUsuario: " + Usr.Rut + " \r Contraseña: " + Password;

                mm.IsBodyHtml = true;
                mm.BodyEncoding = System.Text.Encoding.Default;

                System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(smtp, 25);

                smtpClient.Credentials = new System.Net.NetworkCredential(smtpUserName,smtpPassword);

                smtpClient.EnableSsl = false;
                smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                smtpClient.Send(mm);
            }
            catch(Exception ex)
            {
                throw new Exception(ex.InnerException.Message,ex);

            }
        }
开发者ID:enzoburga,项目名称:pimesoft,代码行数:32,代码来源:NotificacionEmail.cs

示例11: NotificarCambioEMail

        internal void NotificarCambioEMail(SendaPortal.BussinesRules.ConfirmacionEMail confirmacion)
        {
            try
            {
                string dominioPrincipal = System.Configuration.ConfigurationManager.AppSettings["DominioPrincipal"];
                System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
                mm.From = new System.Net.Mail.MailAddress(mailFrom);
                mm.To.Add(confirmacion.Email);
                mm.Subject = "CONFIRMACIÓN DE CAMBIO DE EMAIL DE SENDA PORTAL";
                mm.Body = @"<html><body><span style=""font-size: 10pt; font-family: Verdana"">" + confirmacion.Usuario.Nombres + "<br /><br /> Usted ha solicitado el cambio de su dirección de correo electrónico de Senda Portal. Para confirmar el cambio debe hacer click en el siguiente link:<br /><br /></span><a href=\"http://" + dominioPrincipal + "/MiSendaPortal/ConfirmacionCambioEMail.aspx?Hash=" + confirmacion.Hash + " \"><span style=\"font-size: 10pt; font-family: Verdana\">Confirmar cambio de E-Mail</span></a><span style=\"font-size: 10pt; font-family: Verdana\"></span></body></html>";

                mm.IsBodyHtml = true;
                mm.BodyEncoding = System.Text.Encoding.Default;

                System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(smtp, 25);

                smtpClient.Credentials = new System.Net.NetworkCredential(smtpUserName, smtpPassword);

                smtpClient.EnableSsl = false;
                smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                smtpClient.Send(mm);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.InnerException.Message, ex);

            }
        }
开发者ID:enzoburga,项目名称:pimesoft,代码行数:28,代码来源:NotificacionEmail.cs

示例12: ConfirmMail

 public ActionResult ConfirmMail([Bind(Exclude = "AuthCode")] string uid, UserInfo userinfo)
 {
     try
     {
         using (System.Transactions.TransactionScope transaction = new System.Transactions.TransactionScope())
         {
             userinfo = db.UserInfo.FirstOrDefault(p => p.Uid == uid);
             userinfo.Email = Request["newmail"];
             userinfo.AuthCode = Guid.NewGuid().ToString();
             UpdateModel(userinfo);
             db.SubmitChanges();
             System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient("smtp.qq.com", 25);
             sc.Credentials = new System.Net.NetworkCredential("342354548", "0oO0oO");
             sc.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
             string verify_url = new Uri(Request.Url, System.Web.Routing.RouteTable.Routes.GetVirtualPath
                 (Request.RequestContext, new System.Web.Routing.RouteValueDictionary
                     (new { action = "Verify", authCode = userinfo.AuthCode })).VirtualPath).AbsoluteUri;
             sc.Send("[email protected]", userinfo.Email, "会员注册确认信", verify_url);
             transaction.Complete();
         }
         Session["CurrentUser"] = null;
         return Content("验证邮件已发出,请验证后重新登录!");
     }
     catch (Exception ex)
     {
         ex.ToString();
         return Content("验证邮箱不存在,请重新填写!");
     }
 }
开发者ID:zl2928511,项目名称:OnlineMusic,代码行数:29,代码来源:MemberController.cs

示例13: Send

        /// <summary>
        /// 네이버 계정으로 메일을 발송합니다.
        /// </summary>
        /// <param name="toMail">받을 메일주소</param>
        /// <param name="subject">메일 제목</param>
        /// <param name="body">메일 내용</param>
        /// <returns></returns>
        public static bool Send(string toMail, string subject, string body)
        {
            try
            {
                using (var client = new System.Net.Mail.SmtpClient(SmtpMailAddress))
                {
                    client.Credentials = new System.Net.NetworkCredential(GoogleAccountID, GoogleAccountPwd);
                    client.EnableSsl = true;
                    client.Port = 587;

                    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                    message.Subject = subject;
                    message.From = new System.Net.Mail.MailAddress(FromMail);
                    message.To.Add(toMail);
                    message.IsBodyHtml = true;
                    message.Body = body;
                    client.Send(message);
                    return true;
                }
            }
            catch
            {
                return false;
            }
        }
开发者ID:parkheesung,项目名称:SharedPlayer,代码行数:32,代码来源:Mail.cs

示例14: sendMail

 public bool sendMail(string toSb, string toSbName, string mailSub, string mailBody)
 {
     try
     {
         System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
         client.Host = "smtp.mxhichina.com";//smtp server
         client.Port = 25;
         client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
         client.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
         System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress("[email protected]", "systemName");
         System.Net.Mail.MailAddress toAddress = new System.Net.Mail.MailAddress(toSb, toSbName);
         System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage(fromAddress, toAddress);
         mailMessage.Subject = mailSub;
         mailMessage.Body = mailBody;
         mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
         mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
         mailMessage.IsBodyHtml = true;
         mailMessage.Priority = System.Net.Mail.MailPriority.Normal; //级别
         client.Send(mailMessage);
         return true;
     }
     catch
     {
         return false;
     }
 }
开发者ID:chuliam,项目名称:sziit_Research,代码行数:26,代码来源:Mail.cs

示例15: ConfigHotmailAccount

        private async Task ConfigHotmailAccount(IdentityMessage message)
        {                            
            // Credentials:
            var credentialUserName = ConfigurationManager.AppSettings["emailService:Account"];
            var sentFrom = credentialUserName;
            var pwd = ConfigurationManager.AppSettings["emailService:Password"];

            // Configure the client:
            System.Net.Mail.SmtpClient client =
                new System.Net.Mail.SmtpClient("smtp-mail.outlook.com");

            client.Port = 587;
            client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;

            // Create the credentials:
            System.Net.NetworkCredential credentials =
                new System.Net.NetworkCredential(credentialUserName, pwd);

            client.EnableSsl = true;
            client.Credentials = credentials;

            // Create the message:
            var mail =
                new System.Net.Mail.MailMessage(sentFrom, message.Destination);

            mail.Subject = message.Subject;
            mail.Body = message.Body;

            // Send:
            await client.SendMailAsync(mail);
        }
开发者ID:evangistudio,项目名称:OA2B.AuthCabinet,代码行数:32,代码来源:EmailService.cs


注:本文中的System.Net.Mail.SmtpClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。