Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: 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 at 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 at 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
0 OriginalGriff 295
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 Sergey Alexandrovich Kryukov 174
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911

Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 29 Nov 2012
Copyright © CodeProject, 1999-2014
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