使用 vb.net 向 Outlook 发送邮件。但出现错误,例如“指定的字符串不是电子邮件地址所需的格式”如何解决这个问题 Dim Var_from As String = TextBox1.Text Dim to_var As 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'> 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'> </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)