本文介绍了完整发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到问题,我听不懂,请帮助我.

我正在编写发送邮件"代码,但无法发送邮件.
我不知道问题出在哪里



I am facing a problem and I am not able to understand, please help me.

I am writing a Sending Mail code but I am not able send a mail.
I don''t know where is the problem



// Create a Mail Address Type Object for From Email
                 MailAddress sFrom = new MailAddress("[email protected]", "New Message");

               // Create a Mail Address Type Object for To Email
                MailAddress sTo = new MailAddress("[email protected]");

                // Create a Mail Message Type Object for Email and assign values to various properties, like subject, body, mail type.
                MailMessage MyMail = new MailMessage(sFrom, sTo);
                MyMail.Subject = "Subject Text";
                MyMail.Body = "Body Text";
                MyMail.IsBodyHtml = true;
                MyMail.BodyEncoding = Encoding.UTF8;

                //Create a SMTP client type object, Protocol responsible to send emails. And add the address of your email SMTP. Example of Yahoo added.

                SmtpClient SmtpMail = new SmtpClient("smtp.mail.yahoo.com");
                SmtpMail.EnableSsl = true;

                // Decline default credentials and add yours. Your Email (From Email) & Password.
                SmtpMail.UseDefaultCredentials = false;
                SmtpMail.Credentials = new System.Net.NetworkCredential("[email protected]", "xyzpassword");
    
                // Now send email
                try
                {
                    SmtpMail.Send(MyMail);
                }
                catch (Exception o) { }

推荐答案




这篇关于完整发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 08:59