Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all.I am trying to send mail through my vb.net application but I am getting error
"Failure sending mail."Can any1 please help me to solve this?Below is the code which I have written.
Thanx in advance..

VB
Private Sub Send_Mail(ByVal SendTo As String, ByVal Subject As String, ByVal Body As String)
        Dim strFrom As String = "myemail@gmail.com"
        Dim strto As String = SendTo
        Dim strSubject As String = Subject
        Dim strbody As String = Body

        Dim smtp As SmtpClient = New SmtpClient()
        Dim msg As MailMessage = New MailMessage(strFrom, strto, strSubject, strbody)
        msg.IsBodyHtml = True
        smtp.Host = "localhost"
        smtp.Send(msg)
        MsgBox("Mail Sent.")
    End Sub
Posted
Updated 29-Nov-12 0:58am
v3

Probably, you need to set the authorization - very, very few systems will let you send email without knowing which account it is going from.
Have a look here: Sending an Email in C# with or without attachments: generic routine.[^] - it's in C# but the calls are the same in VB
 
Share this answer
 
Comments
Rachna0309 29-Nov-12 6:44am    
Referred the above link but not understanding what changes I need to do in my code...Can you please help me for that.
OriginalGriff 29-Nov-12 7:05am    
Add the authorization part - it's only one line! VB version:
smtp.Credentials = New System.Net.NetworkCredential(credentialUser, credentialPassword)

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