无法将类型 ('string'、'string') 隐式转换为 System.Net.ICredentialsByHost
Cannot implicitly convert type ('string', 'string') to System.Net.ICredentialsByHost
所以我尝试创建一个电子邮件发件人并提供我的帐户信息,但出现了这个错误:
Cannot implicitly convert type ('string', 'string') to System.Net.ICredentialsByHost.
这是代码。
SmtpClient SmtpServer = new SmtpClient("smpt.gmail.com", 587);
SmtpServer.Credentials = ("username", "password"); # The email and password were lighted up with red
MailMessage Mail = new MailMessage();
Mail.From = new MailAddress("from");
出于显而易见的原因,我更改了电子邮件和密码。
您正在尝试将 ValueTuple
转换为 ICredentialsByHost
。需要构造一个新的NetworkCredential实例并在SmtpServer中设置:
NetworkCredential credentials = new NetworkCredential("username", "password");
SmtpServer.Credentials = credentials;
SmtpServer.Credentials
属性 需要一个来自 ICredentialsByHost
接口的对象。 ("username", "password")
无法隐式转换为 ICredentialsByHost
接口的对象。
您可以像这样使用 NetworkCredential
class
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
见this answer
所以我尝试创建一个电子邮件发件人并提供我的帐户信息,但出现了这个错误:
Cannot implicitly convert type ('string', 'string') to System.Net.ICredentialsByHost.
这是代码。
SmtpClient SmtpServer = new SmtpClient("smpt.gmail.com", 587);
SmtpServer.Credentials = ("username", "password"); # The email and password were lighted up with red
MailMessage Mail = new MailMessage();
Mail.From = new MailAddress("from");
出于显而易见的原因,我更改了电子邮件和密码。
您正在尝试将 ValueTuple
转换为 ICredentialsByHost
。需要构造一个新的NetworkCredential实例并在SmtpServer中设置:
NetworkCredential credentials = new NetworkCredential("username", "password");
SmtpServer.Credentials = credentials;
SmtpServer.Credentials
属性 需要一个来自 ICredentialsByHost
接口的对象。 ("username", "password")
无法隐式转换为 ICredentialsByHost
接口的对象。
您可以像这样使用 NetworkCredential
class
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
见this answer