为什么我使用Google

为什么我使用Google

本文介绍了为什么我使用Google SMTP无法发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好
我有以下程序可以使用 smtp.gmail.com:587发送电子邮件。

HiI have following program to send email by using "smtp.gmail.com:587"

namespace TestMailServer
{
    class Program
    {
        static void Main(string[] args)
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
            mail.From = new MailAddress("[email protected]");
            mail.To.Add("[email protected]");
            mail.Subject = "Test Mail";
            mail.Body = "This is for testing SMTP mail";

            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "myPassword");
            SmtpServer.EnableSsl = true;
            SmtpServer.Send(mail);
            Console.WriteLine("Send out");

        }
    }
}

myTest @ gmail.com,myTest2 @ gmail.com确实存在,而[email protected]的密码是myPassword。为什么会出现以下错误:

[email protected], [email protected] are really existing and [email protected]'s password is myPassword. Why I got the following error:


推荐答案

我不确定是什么引起了您的问题。这是我一直用于通过gmail帐户成功发送电子邮件的一些代码:

I'm not sure what is causing your problem. Here is some code I have been using to successfully send email through a gmail account:

const string from = "...";
var fromAddr = new MailAddress(from, "Bug Tracker");
var toAddr = new MailAddress("...@...", "...");
var client = new SmtpClient {
    Host = "smtp.gmail.com",
    Port = 587,
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Timeout = 30 * 1000,
    Credentials = new NetworkCredential(fromAddr.Address, "...")
};
using (var msg = new MailMessage(fromAddr, toAddr)) {
    msg.Subject = "...";
    msg.Body = string.Format("username: {0}\nversion: {1}\n\n{2}", Environment.UserName, Assembly.GetExecutingAssembly().GetName().Version.ToString(3), cbtext);
    client.Send(msg);
}

这篇关于为什么我使用Google SMTP无法发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 02:02