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 0:03am
Edited 29-Nov-12 0: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 Sergey Alexandrovich Kryukov 271
1 OriginalGriff 223
2 nv3 50
3 VJ Reddy 45
4 Mehdi Gholam 45
0 Sergey Alexandrovich Kryukov 6,696
1 OriginalGriff 6,149
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560

Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | 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