【问题标题】:getting error in vb.net while we send mail to outlook using vb.net当我们使用 vb.net 向 Outlook 发送邮件时,在 vb.net 中出现错误
【发布时间】:2013-01-02 05:55:36
【问题描述】:

使用 vb.net 向 Outlook 发送邮件。但出现错误,例如“指定的字符串不是电子邮件地址所需的形式”如何解决这个问题 Dim Var_from As String = TextBox1.Text 将 to_var 调暗为 String = TextBox2.Text

    Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()


    mailMessage.From = New System.Net.Mail.MailAddress("'" + Var_from + "'")
    mailMessage.To.Add("'" + to_var + "'")
    mailMessage.Subject = "xxx"

    Dim content As String = "<html xmlns='http://www.w3.org/1999/xhtml'><head><style type='text/css'>#mytable { padding: 0;   margin: 0;border-right: 1px solid #C1DAD7;border-bottom: 1px solid #C1DAD7;       border-left: 1px solid #C1DAD7;   border-top: 1px solid #C1DAD7;}caption {padding: 0 0 5px 0; width: 700px;font: Bold 11px 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;      text-align: right;}th {   font: bold 11px 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;     color: #4f6b72;      border-right: 1px solid #C1DAD7;border-bottom: 1px solid #C1DAD7;border-left: 1px solid #C1DAD7;border-top: 1px solid #C1DAD7;   letter-spacing: 2px; text-transform: uppercase; text-align: left;       padding: 6px 6px 6px 12px; background: #CAE8EA; }td {  border-right: 0px solid #C1DAD7;  border-bottom: 0px solid #C1DAD7; border-left: 0px solid #C1DAD7;   background: #fff;    padding: 6px 6px 6px 12px;  color: #4f6b72;}</style></head><body><table border='0' cellpadding='0' id='mytable'  width='100%'><tr><th height='74' style='text-align:center; font-size:16px;' colspan='6'>CAS E-mail Confirmation <div style='float:right;'><img src='cid:HDIImage1' width='143' height='62' align='left' alt='' style='position:absolute;top:0pc;'/></div></th></tr><tr><td colspan='6' class='style5'>&nbsp;Dear Customer,<br/><br/> Thank you for  registering CAS. Click the below link to complete your verification process.. <br/><br/><br/>CAS CODE  :  <br/><br/><br/><br/></td></tr>  <tr>    <th colspan='6' class='style5'>&nbsp;</th>  </tr></table></body></html>"

    Dim plainTextView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(content, Nothing, "text/plain")

    mailMessage.AlternateViews.Add(plainTextView)
    Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()

    smtpClient.Host = "xxx"
    smtpClient.Send(mailMessage)

【问题讨论】:

    标签: sendmail vb.net-2010 smtpclient


    【解决方案1】:

    您需要使用普通的电子邮件地址 - 您添加的单引号可能会导致错误。不用额外的引号。

    mailMessage.From = New System.Net.Mail.MailAddress(Var_from)
    mailMessage.To.Add(to_var)
    

    【讨论】:

    • 使用当前代码的表格会发生什么变化?电子邮件是否以纯文本而不是 HTML 形式发送?尝试添加mailMessage.IsBodyHtml = True
    • 正在创建一行表格如何在邮件内容中设置此html代码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-18
    • 1970-01-01
    • 2012-01-16
    • 2014-09-15
    • 2012-09-22
    • 1970-01-01
    相关资源
    最近更新 更多