通过vb.net中的编码发送邮件 [英] Sending mail through coding in vb.net
问题描述
我正在使用以下代码发送邮件,但我的mailBody包含来自数据库的字符串值.它给出了一些错误,例如将字符串值"转换为Double.
请帮帮我.
Hi,
I am using following code to send mail but my mailBody contains the string value which comes from database. It gives some error like "Convertion String "value" to Double".
Please help me out.
Subject = "Visitor Appointment"
Message = "<HTML><BODY>" _
& "Dear Sir,<BR>" _
& "<BR>" _
& "Visitor want to meet you<BR>" _
& "<B>Visitor Name: </B>" & +EmployeetoMeet.ToString() + +"<BR>" _
& "<B>Visitor Contact No: </B>" & +EmpMobileNo.ToString() + "<BR>" _
& "<BR>" _
& "Thanks & Regards,<BR>" _
& "iSpirit Tech<BR>" _
& "</BODY></HTML>"
Dim SmtpClient As New SmtpClient()
SmtpClient.Host = Smtp
SmtpClient.Port = PortNo
Dim Mail As New MailMessage
Dim mailAdd As New MailAddress(MailAdress)
Mail.From = mailAdd
Mail.To.Add(EmpmailAddress)
Mail.Subject = Subject
Mail.Body = Message
Mail.IsBodyHtml = True
Mail.Priority = MailPriority.Normal
SmtpClient.EnableSsl = True
SmtpClient.Credentials = New Net.NetworkCredential(MailAdress, Password)
SmtpClient.Send(Mail)
MessageBox.Show(" Your message has been sent successfully !", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information)
推荐答案
尝试一下
Try out this
Subject = "Visitor Appointment"
Message = "<HTML><BODY>" _
& "Dear Sir,<BR>" _
& "<BR>" _
& "Visitor want to meet you<BR>" _
& "<B>Visitor Name: </B>" & EmployeetoMeet.ToString() & "<BR>" _
& "<B>Visitor Contact No: </B>" & EmpMobileNo.ToString() & "<BR>" _
& "<BR>" _
& "Thanks & Regards,<BR>" _
& "iSpirit Tech<BR>" _
& "</BODY></HTML>"
您正在用VB编写代码,因此对于串联字符串,应使用& 而不是 +
希望对您有所帮助.
You are writing code in VB, so for concatenation string you should use & and NOT +
Hope it helps.
我猜这是这段代码:
I''m guessing it''s this bit of code:
& "<B>Visitor Name: </B>" & +EmployeetoMeet.ToString() + +"<BR>" _ & "<B>Visitor Contact No: </B>" & +EmpMobileNo.ToString() + "<BR>" _
有时您正在使用&进行连接,但是您那里有一堆+号....它可能试图将字符串转换为双精度,因为它认为您想执行数学加法运算.除去EmployeetoMeet.ToString()
之前的+号,并将之后的+号转换为单个&.
Sometimes you are using & to concat but you have a bunch of + signs in there....it''s probably trying to convert the string to a double because it thinks you want to perform a mathematical addition. Get rid of the + signs before EmployeetoMeet.ToString()
and convert the + signs after into a single &.
这篇关于通过vb.net中的编码发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!