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


C# System.Net.Mail.SmtpClient.Send方法代码示例

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


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

示例1: SendMail3

        public static string SendMail3(string strTo, string strSubject, string strText, bool isBodyHtml, string smtpServer, string login, string password, string emailFrom)
        {
            string strResult;
            try
            {
                var emailClient = new System.Net.Mail.SmtpClient(smtpServer)
                    {
                        UseDefaultCredentials = false,
                        Credentials = new System.Net.NetworkCredential(login, password),
                        DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
                    };
                string strMailList = string.Empty;
                string[] strMails = strTo.Split(';');
                foreach (string str in strMails)
                {
                    if ((str != null) && string.IsNullOrEmpty(str) == false)
                    {
                        strMailList += str + "; ";
                        var message = new System.Net.Mail.MailMessage(emailFrom, str, strSubject, strText) { IsBodyHtml = isBodyHtml };
                        emailClient.Send(message);

                    }
                }
                strMailList.TrimEnd(null);

                try
                {
                    var config = new System.Configuration.AppSettingsReader();
                    var cfgValue = (string)config.GetValue("MailDebug", typeof(System.String));
                    if (cfgValue != "")
                    {
                        strText += string.Format("   [SendList: {0}]", strMailList);
                        var message = new System.Net.Mail.MailMessage(emailFrom, "[email protected]", "SiteDebug [" + cfgValue + "]: " + strSubject, strText) { IsBodyHtml = isBodyHtml };
                        emailClient.Send(message);
                    }
                    else
                    {
                        strText += string.Format("   [SendList: {0}]", strMailList);
                        var message = new System.Net.Mail.MailMessage(emailFrom, "[email protected]", "SiteDebug: " + strSubject, strText) { IsBodyHtml = isBodyHtml };
                        emailClient.Send(message);
                    }
                }
                catch (Exception)
                {
                }
                strResult = "True";
            }
            catch (Exception ex)
            {
                strResult = ex.Message + " at SendMail";
            }
            return strResult;
        }
开发者ID:AzarinSergey,项目名称:learn,代码行数:53,代码来源:SendMail.aspx.cs

示例2: Enviar

 public void Enviar(string Correo, string Nombre, string Usuario,string Contraseña,string curso,string periodo)
 {
     System.Net.Mail.MailMessage correo = new System.Net.Mail.MailMessage();
     correo.From = new System.Net.Mail.MailAddress("[email protected]");
     correo.To.Add(Correo);
     string sub = "Tutorias compu informa";
     string tex = "Buenas " + Nombre + ",\n\n" + " Se le informa que se aprobó como tutor para el curso "
         + curso +" en el periodo "
         + periodo + ".\n" + "Por lo tanto se le indica que su nombre de ususario será:" + "\n " + Usuario  +"\n " +
         " Y la contraseña será: "+"\n " + Contraseña + "\n\n" + "Puede ingresar al sistema una vez que inicie el periodo para el cual se le aprobó la tutoría y cambiar la contraseña.";
     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]", "[email protected]");
     smtp.EnableSsl = false;
     smtp.Port = 587;
     smtp.EnableSsl = true;
     try
     {
         smtp.Send(correo);
     }
     catch (Exception ex)
     {
         var a = ex;
     }
 }
开发者ID:Eur,项目名称:Proyecto,代码行数:34,代码来源:FuncionarioApiController.cs

示例3: 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

示例4: 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

示例5: 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

示例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: SendMail

        /// <summary>
        /// �����ʼ�
        /// </summary>
        /// <param name="toMails">�����������б�</param>
        /// <param name="body">�ʼ�����</param>
        /// <param name="title">����</param>
        /// <param name="isHtml">�����Ƿ���HTML����</param>
        /// <param name="item">����</param>
        /// <param name="mailServerInfo">�ʼ���������Ϣ</param>
        /// <returns></returns>
        public static bool SendMail(string toMails, string body, string title, bool isHtml, System.Net.Mail.Attachment attachment, MailServerInfo mailServerInfo)
        {
            if (String.IsNullOrEmpty(toMails) ||
                !IsEmailFormat(toMails, EmailRegexStyle.multipemail) ||
                String.IsNullOrEmpty(body) ||
                String.IsNullOrEmpty(title))
            {
                throw new Exception("�ʼ�����ʧ�ܣ���Ϣ��������");
            }

            System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
            mailMessage.From = new System.Net.Mail.MailAddress(mailServerInfo.Email, mailServerInfo.DisplayName, System.Text.Encoding.UTF8);
            mailMessage.To.Add(toMails);
            mailMessage.Subject = title;
            mailMessage.Body = body;
            mailMessage.IsBodyHtml = isHtml;

            if (attachment != null)
                mailMessage.Attachments.Add(attachment);

            mailMessage.SubjectEncoding = System.Text.Encoding.Default;
            mailMessage.BodyEncoding = System.Text.Encoding.Default;

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

            client.Host = mailServerInfo.MailServerName;
            client.Port = mailServerInfo.MailServerPort;
            client.UseDefaultCredentials = true;
            client.Credentials = new System.Net.NetworkCredential(mailServerInfo.UserLoginName, mailServerInfo.Password);
            client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            client.Send(mailMessage);

            return true;
        }
开发者ID:ZhaiQuan,项目名称:Zhai,代码行数:44,代码来源:WebUtil.cs

示例8: 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

示例9: 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

示例10: 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

示例11: SendMail

        protected void SendMail()
        {
            // Gmail Address from where you send the mail
            var fromAddress = "[email protected]";
            // any address where the email will be sending
            var toAddress = "[email protected]";

            //Password of your gmail address
            const string fromPassword = "allensmith";

            // Passing the values and make a email formate to display
            string mysubject = subject.Text.ToString();
            string body = "From: " + yourname.Text + "\n";
            body += "Email: " + youremail.Text + "\n";
            body += "Subject: " + subject.Text + "\n";
            body += "Question: \n" + comment.Text + "\n";
            // smtp settings
            var smtp = new System.Net.Mail.SmtpClient();
            {

                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.EnableSsl = true;
                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                smtp.Credentials = new System.Net.NetworkCredential(fromAddress, fromPassword);
                smtp.Timeout = 20000;
            }
            // Passing values to smtp object
            smtp.Send(fromAddress, toAddress, mysubject, body);
        }
开发者ID:brokentriangle,项目名称:brokentriangle.github.io,代码行数:30,代码来源:Sample+07.aspx.cs

示例12: Button1_Click

        protected void Button1_Click(object sender, EventArgs e)
        {
            sBody = "Dear "+txtRecipientName.ToString();

            sBody += System.IO.File.ReadAllText(@"c:\users\student\documents\visual studio 2012\Projects\MvcApplication1\MvcApplication1\Email.txt");

            sBody += "\n\n http://localhost:49394//RefLanding.aspx";
            sBody += "\n\nPasscode : yess";

            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            message.To.Add(txtRecipientEmail.Text.ToString());
            message.Subject = "Confidential Personal Enquiry for "+"Applicant Name";
            message.From = new System.Net.Mail.MailAddress("[email protected]");
            message.Body = sBody;
            System.Net.Mail.SmtpClient mySmtpClient = new System.Net.Mail.SmtpClient();
            System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("[email protected]", "project9password");
            mySmtpClient.Host = "smtp.gmail.com";  //Have specified the smtp host name
            mySmtpClient.UseDefaultCredentials = false;
            mySmtpClient.Port = 587;
            mySmtpClient.Credentials = myCredential;
            mySmtpClient.EnableSsl = true;
            mySmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

               // System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("email.usc.edu");
               mySmtpClient.Send(message);
        }
开发者ID:pree011235,项目名称:577A_Team9,代码行数:26,代码来源:GenerateEmail.aspx.cs

示例13: EnviarEmail

        public static void EnviarEmail(List<string> Destinatarios, String Mensaje, string Asunto, bool BodyHtml)
        {
            System.Net.Mail.SmtpClient cliente = new System.Net.Mail.SmtpClient();

            cliente.Host = "smtp.gmail.com";
            cliente.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            cliente.Port = 25;
            cliente.EnableSsl = true;
            cliente.UseDefaultCredentials = false;
            cliente.Credentials = new System.Net.NetworkCredential("[email protected]", "Camila123*");
            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();

            foreach (string dest in Destinatarios)
            {
                mail.To.Add(dest);
            }
            mail.From = new System.Net.Mail.MailAddress("[email protected]", "Sistema", System.Text.Encoding.UTF8);
            mail.Body = Mensaje;
            mail.Subject = Asunto;
            mail.IsBodyHtml = BodyHtml;
            try
            {
                cliente.Send(mail);
            }
            catch
            {

            }
        }
开发者ID:simadine,项目名称:simad,代码行数:29,代码来源:Utils.cs

示例14: mailSend

        public static bool mailSend(string host, bool ssl, string from, string[] toList, string subject, string body)
        {
            System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient();
            mail.Host = host;//smtp
            //mail.Credentials = new System.Net.NetworkCredential(userName, pwd);
            //mail.EnableSsl = ssl;//发送连接套接层是否加密 例如用gmail发是加密的
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            message.From = new System.Net.Mail.MailAddress(from);

            for (int i = 0; i < toList.Length; i++)
            {
                if (toList[i] != string.Empty)
                {
                    message.To.Add(toList[i]);
                }
            }

            message.Body = body;
            message.Subject = subject;
            message.SubjectEncoding = System.Text.Encoding.GetEncoding("gb2312");
            message.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");
            message.IsBodyHtml = true;
            try
            {
                mail.Send(message);
                return true;
            }
            catch
            {
                return false;
            }
        }
开发者ID:pcstx,项目名称:OA,代码行数:32,代码来源:SendEmail.cs

示例15: SendMail

        public static void SendMail(string emailsTo, string subject, string body, string strAttachPath)
        {
            if (!string.IsNullOrEmpty(emailsTo))
              {
            System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage();
            System.Net.Mail.Attachment attach = null;

            // compose the email message
            email.IsBodyHtml = true;
            email.From = new System.Net.Mail.MailAddress("\"Autoccasion Last Cars\" <" + SmtpConnection.SmtpFrom + ">");
            int i = 0;
            foreach (var emailAddress in emailsTo.Split(Convert.ToChar(";")).ToList())
            {
              if (emailAddress.IndexOf("@") > 0)
            email.To.Add(emailAddress.Trim());
            }
            email.Subject = subject;
            email.Body = body;

            if (strAttachPath.Length > 0)
            {
              attach = new System.Net.Mail.Attachment(strAttachPath);
              email.Attachments.Add(attach);
            }

            var client = new System.Net.Mail.SmtpClient(SmtpConnection.SmtpServer, SmtpConnection.SmtpPort) { EnableSsl = SmtpConnection.SmptUseSSL };
            if ((SmtpConnection.SmtpUser.Length > 0) & (SmtpConnection.SmtpPass.Length > 0))
              client.Credentials = new System.Net.NetworkCredential(SmtpConnection.SmtpUser, SmtpConnection.SmtpPass);

            // send the email
            client.Send(email);
              }
        }
开发者ID:xzc3ss,项目名称:Zaza,代码行数:33,代码来源:CoreEmail.cs


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