C#。无法发送电子邮件。请帮助

时间:2019-09-21 13:07:34

标签: c# smtp

尝试了多种使用C#发送邮件的方法。没有人帮助。一路弄皱。没有人帮助。我非常希望找到会帮助我的人。 在编写代码(下面的代码)时,发送时会剔除“错误发送电子邮件”或“链接到对象未指向该对象的实例。”

已尝试: 1.将英文计算机名称添加到app.config 2.尝试了一堆插件和API类型MailJet,MailKit等 3.尝试更改端口。 (25至465) 4.我尝试了很多代码。但是我无法证明这一点。但添加法院))

string from = "***@gmail.com";
string to = "***@yandex.ru";
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
            mail.To.Add(to);
            mail.From = new MailAddress(from, "One Ghost", System.Text.Encoding.UTF8);
            mail.Subject = "This is a test mail";
            mail.SubjectEncoding = System.Text.Encoding.UTF8;
            mail.Body = "This is Email Body Text";
            mail.BodyEncoding = System.Text.Encoding.UTF8;
            mail.IsBodyHtml = true;
            mail.Priority = MailPriority.High;

            SmtpClient client = new SmtpClient();
            //Add the Creddentials- use your own email id and password

            client.Credentials = new System.Net.NetworkCredential(from, "Password");

            client.Port = 587; // Gmail works on this port
            client.Host = "smtp.gmail.com";
            client.EnableSsl = true; //Gmail works on Server Secured Layer
            try
            {
                client.Send(mail);
            }
            catch (Exception ex)
            {
                Exception ex2 = ex;
                string errorMessage = string.Empty;
                while (ex2 != null)
                {
                    errorMessage += ex2.ToString();
                    ex2 = ex2.InnerException;
                }
                HttpContext.Current.Response.Write(errorMessage);
            }

我需要在yandex.ru上发送mail.ru,但如果不能发送,那么我们可以在同一yandex.ru上发送yandex.ru。需要可以使用的现成代码,或者至少直接提示在哪里进行挖掘。 (对不起,英语,这是Google翻译)

0 个答案:

没有答案