Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

VB
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)
Posted
Updated 15-Mar-11 4:10am
v2

Try out this

XML
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>"


You are writing code in VB, so for concatenation string you should use & and NOT +
Hope it helps.
 
Share this answer
 
Comments
Parshu2378 15-Mar-11 11:20am    
Thank you so much
That's Aragon 16-Mar-11 1:17am    
You are welcome. Glad to know that it helps you. :)
I'm guessing it's this bit of code:
& "<B>Visitor Name: </B>" & +EmployeetoMeet.ToString() + +"<BR>" _                & "<B>Visitor Contact No: </B>" & +EmpMobileNo.ToString() + "<BR>" _


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 &.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900