本文介绍了smtpclient的特殊字符密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Vb(2005年和2013年)。 我使用此代码发送电子邮件:
Dim SmtpServer 作为 新 SmtpClient() Dim mail As New MailMessage() SmtpServer.Credentials = 新 _ Net.NetworkCredential( username@gmail, 密码) SmtpServer.Port = 587 SmtpServer.Host = smtp.gmail mail = 新 MailMessage() mail.From = 新 MailAddress( YOURusername@gmail) mail。要 .Add( TOADDRESS) mail.Subject = 测试邮件 mail.Body = 这是用于测试来自GMAIL的SMTP邮件 SmtpServer.Send(mail)它工作正常,但只有在凭证密码没有特殊字符如'@','!',... 我尝试了什么: 我试过像gmail这样的smtp服务器,注册,ecc。 我试过 2.0和 4.5.1 非常感谢!
解决方案尝试传递密码d用双引号(必须先用另一个双引号告诉VB它不是字符串的结尾): Net.NetworkCredential( username@gmail, password)
Hi, I use Vb (2005 and 2013). I use this code sending emails:
Dim SmtpServer As New SmtpClient() Dim mail As New MailMessage() SmtpServer.Credentials = New _ Net.NetworkCredential("username@gmail", "password") SmtpServer.Port = 587 SmtpServer.Host = "smtp.gmail" mail = New MailMessage() mail.From = New MailAddress("YOURusername@gmail") mail.To.Add("TOADDRESS") mail.Subject = "Test Mail" mail.Body = "This is for testing SMTP mail from GMAIL" SmtpServer.Send(mail)and it works fine but only if credential password has got no special characters like '@','!',... What I have tried: I have tried with some smtp servers like gmail, register, ecc. I have tried both with 2.0 and 4.5.1 Thank a lot!
解决方案 Try to pass the password enclosed by double quotes (which must be each preceeded by another double quote to tell VB that it is not the end of the string): Net.NetworkCredential("username@gmail", """password""")更多推荐
smtpclient的特殊字符密码
发布评论