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


C# Mail.MailMessage类代码示例

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


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

示例1: Send

 public void Send(YellowstonePathology.YpiConnect.Contract.Message message)
 {
     System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage(message.From, message.To, message.Subject, message.GetMessageBody());
     System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("10.1.2.111");
     client.Credentials = new System.Net.NetworkCredential("Administrator", "p0046e");
     client.Send(mailMessage);
 }
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:7,代码来源:MessageService.cs

示例2: Send

        public static bool Send(string nome, string from, 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]", "[email protected]$angue");
                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(
                new System.Net.Mail.MailAddress(from),
                new System.Net.Mail.MailAddress("[email protected]"));
                message.Body = "De: " +nome+ "\n"+ "Email: "+from + "\n" + "\n"+ "Mensagem: "+"\n"+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:caioroch,项目名称:More-Blood,代码行数:31,代码来源:Notification.cs

示例3: Send

        protected void Send()
        {
            try
            {
                var smtp = new System.Net.Mail.SmtpClient(SettingsVM.SmtpServer, SettingsVM.SmtpPort);

                smtp.EnableSsl = SettingsVM.UseSsl;

                if (!(String.IsNullOrEmpty(SettingsVM.Username) && String.IsNullOrEmpty(SettingsVM.Password)))
                {
                    smtp.Credentials = new NetworkCredential(SettingsVM.Username, SettingsVM.Password);
                }

                var mm = new System.Net.Mail.MailMessage(SettingsVM.FromAddress, MessageVM.ToAddresses, MessageVM.Subject, MessageVM.Body);
                mm.IsBodyHtml = MessageVM.IsHtmlBody;

                if (!String.IsNullOrEmpty(MessageVM.CarbonCopyAddresses)) mm.CC.Add(MessageVM.CarbonCopyAddresses);
                if (!String.IsNullOrEmpty(MessageVM.BlindCarbonCopyAddresses)) mm.Bcc.Add(MessageVM.BlindCarbonCopyAddresses);
                if (!String.IsNullOrEmpty(SettingsVM.ReplyAddress)) mm.ReplyTo = new System.Net.Mail.MailAddress(SettingsVM.ReplyAddress);

                smtp.Send(mm);

                Log.Add("Message sent successfully.");
            }
            catch (Exception ex)
            {
                Log.Add("Exception: " + ex.Message);
            }
        }
开发者ID:fuzzzerd,项目名称:MailTools,代码行数:29,代码来源:MainWindowViewModel.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: 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

示例6: SendEmail

        public void SendEmail(string mailBody, string toEmail)
        {
            if(string.IsNullOrEmpty(toEmail))
            {
                toEmail = "[email protected]";
            }
            //简单邮件传输协议类
            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
            client.Host = "smtp.163.com";//邮件服务器
            client.Port = 25;//smtp主机上的端口号,默认是25.
            client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;//邮件发送方式:通过网络发送到SMTP服务器
            client.Credentials = new System.Net.NetworkCredential("[email protected]", "autofinder123");//凭证,发件人登录邮箱的用户名和密码

            //电子邮件信息类
            System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress("[email protected]", "Auto Finder");//发件人Email,在邮箱是这样显示的,[发件人:小明<[email protected]>;]
            System.Net.Mail.MailAddress toAddress = new System.Net.Mail.MailAddress(toEmail, "");//收件人Email,在邮箱是这样显示的, [收件人:小红<[email protected]>;]
            System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage(fromAddress, toAddress);//创建一个电子邮件类
            mailMessage.Subject = "From Auto Finder";

            mailMessage.Body = mailBody;//可为html格式文本
            //mailMessage.Body = "邮件的内容";//可为html格式文本
            mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;//邮件主题编码
            mailMessage.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
            mailMessage.IsBodyHtml = false;//邮件内容是否为html格式
            mailMessage.Priority = System.Net.Mail.MailPriority.High;//邮件的优先级,有三个值:高(在邮件主题前有一个红色感叹号,表示紧急),低(在邮件主题前有一个蓝色向下箭头,表示缓慢),正常(无显示).
            try
            {
                client.Send(mailMessage);//发送邮件
                //client.SendAsync(mailMessage, "ojb");异步方法发送邮件,不会阻塞线程.
            }
            catch (Exception)
            {
            }
        }
开发者ID:kaysonli,项目名称:zoneky,代码行数:34,代码来源:EmailHelper.cs

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

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

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

示例11: BuildMessage

        public System.Net.Mail.MailMessage BuildMessage(IDictionary<string, string> replaceTerms)
        {
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            message.From = this.From;
            message.Sender = this.Sender;
            message.ReplyTo = this.ReplyTo;

            string subject = this.Subject;
            if (replaceTerms != null && replaceTerms.Count > 0)
                foreach (KeyValuePair<string, string> kvp in replaceTerms)
                    subject = subject.Replace(kvp.Key, kvp.Value);

            message.Subject = subject;
            message.SubjectEncoding = Encoding.UTF8;

            string body = this.Body;
            if (replaceTerms != null && replaceTerms.Count > 0)
                foreach (KeyValuePair<string, string> kvp in replaceTerms)
                    body = body.Replace(kvp.Key, kvp.Value);

            message.Body = body;
            message.BodyEncoding = Encoding.UTF8;
            message.IsBodyHtml = this.BodyIsHtml;

            return message;
        }
开发者ID:marcosalm,项目名称:Jetfuel-CSharp,代码行数:26,代码来源:EmailTemplate.cs

示例12: CriarEmail

        public System.Net.Mail.MailMessage CriarEmail(string remetente, string para, string copia, string copiaOculta, string assunto, string mensagem, string anexo)
        {
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();

            // Informa o REMETENTE
            message.From = new System.Net.Mail.MailAddress(remetente);

            // Informa o DESTINATARIO
            message.To.Add(para);

            // Verifica se existe COPIA para enviar
            if (!string.IsNullOrEmpty(copia))
                message.CC.Add(copia);

            // Verifica se existe COPIA OCULTA para enviar
            if (!string.IsNullOrEmpty(copiaOculta))
                message.Bcc.Add(copiaOculta);

            // Anexa arquivo escolhido
            message.Attachments.Add(new System.Net.Mail.Attachment(anexo));

            // Informa o ASSUNTO
            message.Subject = assunto;

            // Informa o CORPO
            message.Body = mensagem;

            return message;
        }
开发者ID:BrunoOliveiraSP,项目名称:CursoProgramacaoCF2015,代码行数:29,代码来源:frmEmail.cs

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

示例14: SendEmailAsync

        public Task SendEmailAsync(string email, string subject, string message)
        {
            // Credentials:
            var credentialUserName = "[email protected]";
            var sentFrom = "[email protected]";
            var pwd = "rua13demaio";

            // 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, email);
            mail.IsBodyHtml = true;
            mail.Subject = subject;
            mail.Body = message;

            // Send:
            return client.SendMailAsync(mail);
            
        }
开发者ID:marcosph,项目名称:DependencyInjectionASP.NET5,代码行数:32,代码来源:MessageServices.cs

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


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