vps
vps

Reputation: 1367

getting error in vb.net while we send mail to outlook using vb.net

using vb.net to send mail to outlook. but am getting error like "the specified string is not in the form required for an e-mail address" How to solve this problem 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'>&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)

Upvotes: 0

Views: 528

Answers (1)

djhayman
djhayman

Reputation: 1167

You need to use normal email addresses - the single quotes that you are adding might be causing the error. Do it without the extra quotes.

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

Upvotes: 1

Related Questions