本文介绍了如何在按钮单击事件上使用C清晰编码从ASP.net发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

我正在使用SMTP发送邮件,单击事件"按钮.

Hi Friends,

I am using SMTP to send a mail on button click Event .

MailMessage mailMessage = new MailMessage();
            mailMessage.From = new MailAddress(Convert.ToString(ConfigurationSettings.AppSettings["UpdateMailFrm"]));
            mailMessage.To.Add(Convert.ToString(ConfigurationSettings.AppSettings["UpdateMailTo"]));
            
            mailMessage.IsBodyHtml = true;
            mailMessage.Subject = " HP Stacking Profile Update ";
            mailMessage.Body = mailtxt;
            string host = Convert.ToString(ConfigurationSettings.AppSettings["BytechSmtpServer"]);
            SmtpClient SmtpMail = new SmtpClient(host);                  
            SmtpMail.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
            SmtpMail.Send(mailMessage);

            string nowdate = System.DateTime.Now.Date.ToString("dd_MM_yyyy");
            string path = Server.MapPath("~/") + "LogFile/" + nowdate + ".txt";
            string text1 = " Page :Mail Date and Time :" + System.DateTime.Now.ToString("dd-MM-yyyy hh:ss:mm");
            text1 = text1 + " Message :" + "Message successfully Sent\r\n";
            File.AppendAllText(path, text1);



以上代码是我在我的项目中使用的代码.它不会引发任何错误,但也不会发送邮件.我已声明发件人要在我的Web.Config文件中邮寄邮件和主机(BytechSmtpServer).

因此,有人可以建议我解决此问题.



The Above Code is which i have used in My project . Its not throwing any Error but its not sending the Mail also. I have declared the From & To mail''s and Host(BytechSmtpServer) in my Web.Config File .

So can any one suggest me to fix this issues .

推荐答案

MailMessage oMsg = new MailMessage();
               oMsg.From = new MailAddress("[email protected]", "xxx");
               oMsg.To.Add(new MailAddress("[email protected]", "xxx"));
               oMsg.Subject = "Packet Parsing Problem";
               oMsg.Body = " Problem Occuread test mail";
               oMsg.SubjectEncoding = System.Text.Encoding.UTF8;
               oMsg.BodyEncoding = System.Text.Encoding.UTF8;
               oMsg.IsBodyHtml = false;
               oMsg.Priority = MailPriority.High;

               SmtpClient oSmtp = new SmtpClient("smtp.gmail.com", 587);
               oSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;
               oSmtp.EnableSsl = true;

               NetworkCredential oCredential = new NetworkCredential("[email protected]", "123456aA");
               oSmtp.UseDefaultCredentials = false;
               oSmtp.Credentials = oCredential;
               oSmtp.Send(oMsg);




谢谢




Thanks


这篇关于如何在按钮单击事件上使用C清晰编码从ASP.net发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 06:35