Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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..
 
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 29-Nov-12 0:03am
Edited 29-Nov-12 0:58am
ridoy51.9K
v3
Rate this: bad
good
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
  Permalink  
Comments
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 410
1 Maciej Los 300
2 OriginalGriff 288
3 CHill60 190
4 Sinisa Hajnal 180


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