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.
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
. Need to construct a new NetworkCredential instance and set it in SmtpServer:
NetworkCredential credentials = new NetworkCredential("username", "password");
SmtpServer.Credentials = credentials;
The SmtpServer.Credentials
property needs an object that interface from the ICredentialsByHost
interce. ("username", "password")
can't be implicitly converted to an object that ICredentialsByHost
interface.
You could use the NetworkCredential
class like this
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
See this answer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.