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


C# SmtpClient.SendAsync方法代码示例

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


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

示例1: sendEmail

        public void sendEmail(String targetEmail, String targetName, String targetLogin, String password)
        {
            String body;

            body = "Dear " + targetName + ", \n\n";
            body += "Thank you for using our application! \n";
            body += "Below is your authentication information: \n\n";
            body += "\t Your login: " + targetLogin + "\n";
            body += "\t Your new password: " + password + "\n\n";
            body += "----------------\n";
            body += "Sincerely, Software Development Team";

            try
            {
                SmtpClient client = new SmtpClient("smtp.gmail.com");
                client.Port = 587;
                client.EnableSsl = true;
                client.Timeout = 100000;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Credentials = new NetworkCredential(
                  "[email protected]", "humber123");
                MailMessage msg = new MailMessage();
                msg.To.Add(targetEmail);
                msg.From = new MailAddress("[email protected]");
                msg.Subject = "NEW PASSWORD REQUEST";
                msg.Body = body;
                client.SendAsync(msg, "message");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
开发者ID:koryakinp,项目名称:NETproject,代码行数:34,代码来源:frm_restorePassword.cs

示例2: MailGonder

        private void MailGonder()
        {
            MailMessage ePosta = new MailMessage();
            ePosta.From = new MailAddress("[email protected]");
            ePosta.To.Add("[email protected]");
            //ePosta.Attachments.Add(new Attachment(@"C:\deneme.xls"));
            ePosta.Subject = textBox2.Text;
            ePosta.Body = textBox3.Text;
            SmtpClient smtp = new SmtpClient();
            smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "glsh6662169626gs");
            smtp.Port = 587;
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            object userState = ePosta;
            //bool kontrol = true;

            try
            {
                smtp.SendAsync(ePosta, (object)ePosta);
                MessageBox.Show("Mailiniz başarıyla gönderildi");
            }
            catch (SmtpException ex)
            {
                //kontrol = false;
                System.Windows.Forms.MessageBox.Show(ex.Message, "Mail Gönderme Hatasi");
            }
        }
开发者ID:gulsahcoskun,项目名称:c--project,代码行数:27,代码来源:Formmail.cs

示例3: Send

        public void Send(string addressees, string subject, string body)
        {
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
            if (addressees.IndexOf(',') > -1)
            {
                string[] mails = addressees.Split(',');
                for (int counti = 0; counti < mails.Length; counti++)
                {
                    if (mails[counti].Trim() != "")
                    {
                        msg.To.Add(mails[counti]);
                    }
                }
            }
            else
            {
                msg.To.Add(addressees);
            }

            msg.From = new System.Net.Mail.MailAddress(Config.Addressor, Config.AddressorName, System.Text.Encoding.UTF8);
            msg.Subject = subject;
            msg.SubjectEncoding = System.Text.Encoding.UTF8;
            msg.Body = body;
            msg.BodyEncoding = System.Text.Encoding.UTF8;
            msg.IsBodyHtml = true;
            msg.Priority = MailPriority.High;

            SmtpClient client = new SmtpClient();
            client.Credentials = new System.Net.NetworkCredential(Config.Addressor, Config.AddressorPassword);
            client.Host = Config.SmtpServer;

            object userState = msg;

            client.SendAsync(msg, userState);
        }
开发者ID:piaolingzxh,项目名称:Justin,代码行数:35,代码来源:JMail.cs

示例4: SendAsync

        public Task SendAsync(IdentityMessage message)
        {
            if (ConfigurationManager.AppSettings["EmailServer"] != "{EmailServer}"
                && ConfigurationManager.AppSettings["EmailUser"] != "{EmailUser}"
                && ConfigurationManager.AppSettings["EmailPassword"] != "{EmailPassword}")
            {
                var mailMsg = new MailMessage();

                // To
                mailMsg.To.Add(new MailAddress(message.Destination, ""));

                // From
                mailMsg.From = new MailAddress("[email protected]", "Online Service administrator");

                // Subject and multipart/alternative Body
                mailMsg.Subject = message.Subject;
                var html = message.Body;
                mailMsg.AlternateViews.Add(
                    AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html));

                // Init SmtpClient and send
                var smtpClient = new SmtpClient(ConfigurationManager.AppSettings["EmailServer"], Convert.ToInt32(587));
                var credentials = new NetworkCredential(
                    ConfigurationManager.AppSettings["EmailUser"],
                    ConfigurationManager.AppSettings["EmailPassword"]);
                smtpClient.Credentials = credentials;
                smtpClient.EnableSsl = true;

                return Task.Factory.StartNew(() => smtpClient.SendAsync(mailMsg, "token"));
            }
            return Task.FromResult(0);
        }
开发者ID:benitazz,项目名称:ArchibusPortal,代码行数:32,代码来源:EmailService.cs

示例5: SendMail

        protected void SendMail(MailMessage mail)
        {
            SmtpClient client = new SmtpClient();
            client.EnableSsl = true;

            client.SendAsync(mail, null);
        }
开发者ID:JustinWi,项目名称:pokemon,代码行数:7,代码来源:EmailNotifier.cs

示例6: SendMail

        public static void SendMail(string to, string from, string subject, string body, string[] cc)
        {
            SmtpClient client = new SmtpClient("smtp.gokapara.com");

            client.UseDefaultCredentials = false;
            client.Timeout = 20000;
            client.Port = 25;
            client.EnableSsl = false;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.Credentials = new NetworkCredential("[email protected]", "5224861507Go!");

            MailMessage mail = new MailMessage(from, to);

            mail.IsBodyHtml = true;
            mail.Subject = subject;
            mail.Body = body;
            mail.BodyEncoding = Encoding.UTF8;

            if (cc != null)
            {
                for (int i = 0; i < cc.Length; i++)
                {
                    mail.CC.Add(cc[i]);
                }
            }

            client.SendAsync(mail, null);
        }
开发者ID:xoperator,项目名称:GoKapara,代码行数:28,代码来源:Smtp.cs

示例7: SendMail

        public void SendMail(string from, string to, string cc, 
            string bcc, string subject, string content)
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(from, "Japan Extreme");
            msg.To.Add(to);
            msg.Subject = subject;
            msg.IsBodyHtml = true;
            msg.BodyEncoding = new System.Text.UTF8Encoding();
            msg.Body = content;
            msg.Priority = MailPriority.High;

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            System.Net.NetworkCredential user = new 
                System.Net.NetworkCredential(
                    ConfigurationManager.AppSettings["sender"], 
                    ConfigurationManager.AppSettings["senderPass"]
                    );

            smtp.EnableSsl = true;
            smtp.Credentials = user;
            smtp.Port = 587; //or use 465 
            object userState = msg;

            try
            {
                //you can also call client.Send(msg)
                smtp.SendAsync(msg, userState);
            }
            catch (SmtpException)
            {
                //Catch errors...
            }
        }
开发者ID:vramsngrai1994,项目名称:mkpacific-ltd,代码行数:35,代码来源:MKMail.cs

示例8: SendMessage

        public static bool SendMessage(
            string targetAddress,
            string subject,
            string body)
        {
            bool success = true;

            MailMessage msg = new MailMessage();

            msg.From = new MailAddress(MailConstants.WEB_SERVICE_EMAIL_ADDRESS);
            msg.To.Add(targetAddress);
            msg.Body = body;
            msg.Subject = subject;
            msg.BodyEncoding = System.Text.Encoding.ASCII;
            msg.IsBodyHtml = true;

            try
            {
                SmtpClient smtpClient = new SmtpClient();

                smtpClient.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
                smtpClient.EnableSsl = true;
                smtpClient.SendAsync(msg, subject); // Identify the async message sent by the subject
            }
            catch (System.Exception)
            {
                success = false;
            }

            return success;
        }
开发者ID:ltloibrights,项目名称:AsyncRPG,代码行数:31,代码来源:EMail.cs

示例9: AsyncSendEmail

        /// <summary>
        /// 异步发送邮件
        /// </summary>
        /// <param name="msgFrom">发送者邮件</param>
        /// <param name="msgTo">接收者邮件</param>
        /// <param name="msgSubject">邮件主题</param>
        /// <param name="msgBody">邮件主体内容</param>
        /// <param name="UserName">提供身份验证的用户名</param>
        /// <param name="Password">提供身份验证的密码</param>
        /// <param name="Port">SMTP服务器端口</param>
        /// <param name="SmtpHost">SMTP服务器(如:smtp.163.com; smtp.qq.com; smtp.gmail.com)</param>
        public static bool AsyncSendEmail(String msgFrom, String[] msgTo, String msgSubject, String msgBody, String UserName, String Password, int Port, String SmtpHost, String Domain)
        {
            MailMessage mailMsg = new MailMessage();
            mailMsg.From = new MailAddress(msgFrom);
            foreach (var str in msgTo)
            {
                mailMsg.To.Add(str);
            }
            mailMsg.Subject = msgSubject;
            mailMsg.Body = msgBody;
            mailMsg.BodyEncoding = Encoding.UTF8;
            mailMsg.IsBodyHtml = true;
            mailMsg.Priority = MailPriority.High;

            SmtpClient smtp = new SmtpClient();
            smtp.Credentials = new NetworkCredential(UserName, Password, Domain);
            smtp.Port = Port;
            smtp.Host = SmtpHost;

            smtp.EnableSsl = false;
            smtp.SendCompleted += new SendCompletedEventHandler(smtp_SendCompleted);
            try
            {
                smtp.SendAsync(mailMsg, mailMsg);
                return true; //邮件提交成功(发送成功与否不可知)
            }
            catch //(SmtpException ex)
            {
                //邮件发送异常日志

                return false; //邮件提交失败
            }
        }
开发者ID:kylin589,项目名称:EmePro,代码行数:44,代码来源:MailHelper.cs

示例10: sftpEmail

 private static void sftpEmail()
 {
     message.To.Add(to);
     message.CC.Add(cc);
     message.Subject = subject;
     message.From = new MailAddress(from);
     message.Body = body;
     Attachment data;
     for (int i = 0; i < attachments.Count; i++)
     {
         try
         {
             data = new Attachment(attachments[i].FullName);
             message.Attachments.Add(data);
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
         }
     }
     smtp = new SmtpClient("domino1", 25);
     string userState = "sending email";
     smtp.SendAsync(message, userState);
     smtp.SendCompleted += new SendCompletedEventHandler(emailCompletedCallback);
 }
开发者ID:robertmcconnell2007,项目名称:CCCommunications,代码行数:25,代码来源:Program.cs

示例11: SendAsyncMail

        public static void SendAsyncMail(string to, string subject, string content)
        {
            MailMessage mail = new MailMessage();

            mail.To.Add(new MailAddress(to));

            mail.Subject = subject;
            mail.Body = content;
            mail.IsBodyHtml = true;

            SmtpClient smtpClient = new SmtpClient();
            smtpClient.EnableSsl = true;
            Object state = mail;

            //event handler for asynchronous call
            smtpClient.SendCompleted += new SendCompletedEventHandler(smtpClient_SendCompleted);
            try
            {
                smtpClient.SendAsync(mail, state);
            }
            catch (Exception ex)
            {

            }
        }
开发者ID:kolyan1981by,项目名称:monop,代码行数:25,代码来源:EmailHelpers.cs

示例12: SendAsync

        public Task SendAsync(IdentityMessage message)
        {
            if (ConfigurationManager.AppSettings["EmailServer"] != "{EmailServer}" &&
                ConfigurationManager.AppSettings["EmailUser"] != "{EmailUser}" &&
                ConfigurationManager.AppSettings["EmailPassword"] != "{EmailPassword}")
            {
                System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage();

                // To
                mailMsg.To.Add(new MailAddress(message.Destination, ""));

                // From
                mailMsg.From = new MailAddress("[email protected]", "DurandalAuth administrator");

                // Subject and multipart/alternative Body
                mailMsg.Subject = message.Subject;
                string html = message.Body;
                mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html));

                // Init SmtpClient and send
                SmtpClient smtpClient = new SmtpClient(ConfigurationManager.AppSettings["EmailServer"], Convert.ToInt32(587));
                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["EmailUser"], ConfigurationManager.AppSettings["EmailPassword"]);
                smtpClient.Credentials = credentials;

                return Task.Factory.StartNew(() => smtpClient.SendAsync(mailMsg, "token"));
            }
            else
            {
                return Task.FromResult(0);
            }
        }
开发者ID:Gionet,项目名称:DurandalAuth,代码行数:31,代码来源:EmailService.cs

示例13: SendEmail

        public static void SendEmail(string emailSubject,string emailContent)
        {
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();

            msg.To.Add("[email protected]");
            //这个地方可以发送给多人,但是没有实现,可以用“,”分割,之后取得每个收件人的地址。
            //也可以抄送给多人。
            msg.Subject = emailSubject;
            msg.From = new MailAddress("[email protected]");
            msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
            msg.Body = emailContent;
            msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
            msg.IsBodyHtml = false;
            msg.Priority = MailPriority.High;
            SmtpClient client = new SmtpClient();
            client.Credentials = new System.Net.NetworkCredential("[email protected]", "hexiang1993");
            //client.Host = "localhost";//这个发布出去啊。应该是当做了垃圾邮件了。
            client.Host = "smtp.126.com";
            object userState = msg;
            if (msg.Body == "")
            {
                MessageBox.Show("您的留言不能为空哟!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            try
            {
                client.SendAsync(msg, userState);
                MessageBox.Show("提交成功!谢谢您的支持!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                MessageBox.Show("提交出错!请检查网络连接!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
开发者ID:KaminoDice,项目名称:Jovi-s-Software,代码行数:34,代码来源:126SMTP.cs

示例14: SendAsync

        public Task SendAsync(IdentityMessage message)
        {
            if (ConfigurationManager.AppSettings["EmailServer"] != "{EmailServer}" &&
              ConfigurationManager.AppSettings["EmailUser"] != "{EmailUser}" &&
              ConfigurationManager.AppSettings["EmailPassword"] != "{EmailPassword}")
              {
            var mailMsg = new MailMessage();

            mailMsg.To.Add(new MailAddress(message.Destination, ""));

            mailMsg.From = new MailAddress("[email protected]",
              "EnergieNetz Administrator");

            // Subject and multipart/alternative Body
            mailMsg.Subject = message.Subject;

            mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(message.Body, null, MediaTypeNames.Text.Plain));

            // Init SmtpClient and send

            var smtpClient = new SmtpClient
            {
              Host = ConfigurationManager.AppSettings["EmailServer"],
              Port = int.Parse(ConfigurationManager.AppSettings["Port"]), //587,
              EnableSsl = true,
              Credentials = new NetworkCredential(ConfigurationManager.AppSettings["EmailUser"],
            ConfigurationManager.AppSettings["EmailPassword"])
            };

            return Task.Factory.StartNew(() => smtpClient.SendAsync(mailMsg,
              "token"));
              }
              return Task.FromResult(0);
        }
开发者ID:htw-bui,项目名称:EnergieNetz,代码行数:34,代码来源:EmailService.cs

示例15: SendMailMessage

        /// <summary>
        /// �����ʼ�
        /// </summary>
        /// <param name="message">�ʼ�</param>
        /// <param name="isAsync">�Ƿ��첽����</param>
        private void SendMailMessage(MailMessage message, bool isAsync)
        {
            if (message == null)
                throw new ArgumentNullException("message");

            try
            {
                message.IsBodyHtml = true;
                message.BodyEncoding = Encoding.UTF8;

                SmtpClient smtp = new SmtpClient(this.SmtpServer);
                smtp.UseDefaultCredentials = true;
                smtp.Credentials = new System.Net.NetworkCredential(this.UserName, this.Password);
                smtp.Port = this.Port;
                //smtp.EnableSsl = true;

                if (isAsync)
                    smtp.SendAsync(message, null);
                else
                    smtp.Send(message);
            }
            catch (SmtpException)
            {
                throw;
            }
            finally
            {
                message.Dispose();
                message = null;
            }
        }
开发者ID:ahui2012,项目名称:CommonTools,代码行数:36,代码来源:DotNetMail.cs


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