smtpclient的特殊字符密码

编程入门 行业动态 更新时间:2024-10-26 13:31:48
本文介绍了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的特殊字符密码

本文发布于:2023-08-07 10:24:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1318603.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:特殊字符   密码   smtpclient

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!