[英]Cannot implicitly convert type ('string', 'string') to System.Net.ICredentialsByHost
So i tried making an email sender and give my account info and this error showed up:因此,我尝试制作电子邮件发件人并提供我的帐户信息,但出现此错误:
Cannot implicitly convert type ('string', 'string') to System.Net.ICredentialsByHost.
无法将类型 ('string', 'string') 隐式转换为 System.Net.ICredentialsByHost。
This is the code.这是代码。
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");
I changed the email and password for obvious reasons.出于显而易见的原因,我更改了电子邮件和密码。
You are trying to convert a ValueTuple
to ICredentialsByHost
.您正在尝试将
ValueTuple
转换为ICredentialsByHost
。 Need to construct a new NetworkCredential instance and set it in SmtpServer:需要构造一个新的 NetworkCredential 实例并在 SmtpServer 中进行设置:
NetworkCredential credentials = new NetworkCredential("username", "password");
SmtpServer.Credentials = credentials;
The SmtpServer.Credentials
property needs an object that interface from the ICredentialsByHost
interce. SmtpServer.Credentials
属性需要一个与ICredentialsByHost
接口的对象。 ("username", "password")
can't be implicitly converted to an object that ICredentialsByHost
interface. ("username", "password")
不能隐式转换为ICredentialsByHost
接口的对象。
You could use the NetworkCredential
class like this您可以像这样使用
NetworkCredential
类
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
See this answer看到这个答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.