Click here to Skip to main content
11,924,800 members (57,230 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
Hi all.I am trying to send mail through my 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..

Private Sub Send_Mail(ByVal SendTo As String, ByVal Subject As String, ByVal Body As String)
        Dim strFrom As String = ""
        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"
        MsgBox("Mail Sent.")
    End Sub
Posted 29-Nov-12 1:03am
Edited 29-Nov-12 1:58am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151125.3 | Last Updated 29 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100