简体   繁体   English

无法将类型 ('string', 'string') 隐式转换为 System.Net.ICredentialsByHost

[英]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.

相关问题 无法隐式转换类型 'System.Linq.IQueryable<string> '到'字符串'</string> - Cannot implicitly convert type 'System.Linq.IQueryable<string>' to 'string' 无法隐式转换System.Linq.IQueryable类型 <string> 串起来 - Cannot implicitly convert type System.Linq.IQueryable<string> to string 错误“无法将类型&#39;string&#39;隐式转换为&#39;System.Type&#39; - Error"Cannot implicitly convert type 'string' to 'System.Type' 无法将类型&#39;string&#39;隐式转换为&#39;System.Type&#39; - Cannot implicitly convert type 'string' to 'System.Type' 无法将类型&#39;string&#39;隐式转换为&#39;System.Windows.Forms.TextBox&#39; - Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox' 无法将类型&#39;System.Data.Common.DbDataReader&#39;隐式转换为&#39;string&#39; - Cannot implicitly convert type 'System.Data.Common.DbDataReader' to 'string' 无法将类型&#39;string&#39;隐式转换为&#39;System.Data.CommandType&#39; - Cannot implicitly convert type 'string' to 'System.Data.CommandType' 无法将类型System.DirectoryServices.AccountManagement.Principal隐式转换为字符串 - Cannot implicitly convert type System.DirectoryServices.AccountManagement.Principal to string 无法在C#中将类型字符串隐式转换为system.datetime - cannot implicitly convert type string to system.datetime in c# 无法将类型“字符串”隐式转换为“System.DateTime” - Cannot implicitly convert type 'string' to 'System.DateTime'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM