Hi all.I am trying to send mail through my vb.net application but i am getting error "Failure sending mail."
Can any1 help me to solve this problem?Below is the code I have written.

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

Sending internally? Chek if your Firewall letting to use the smtp.

Also there doesn't appear to be any login info there.

        Dim mail As New MailMessage()
        Dim SmtpServer As New SmtpClient
        SmtpServer.Credentials = New Net.NetworkCredential("senders_mail_address@gmail.com", "senders_mail_address_password")
        SmtpServer.Port = 587
        SmtpServer.Host = "smtp.gmail.com"
        SmtpServer.EnableSsl = True
        SmtpServer.EnableSsl = True
        mail.To.Add("receiver_mail_address@gmail.com")
        mail.From = New MailAddress("senders_mail_address@gmail.com")
        mail.Subject = "Mail_Subject_Here"
        mail.Body = TextBox1.Text ' or text what you want to write or get from
        SmtpServer.Send(mail)

Imports System.Net.Mail
Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim EmailMessage As New MailMessage()
    Try
        EmailMessage.From = New MailAddress("Your Gmail account")
        EmailMessage.To.Add("Your email account")
        EmailMessage.Subject = "The Subject"
        EmailMessage.Body = "Put the message here"
        Dim SMTP As New SmtpClient("smtp.gmail.com")
        SMTP.Port = 587
        SMTP.EnableSsl = True
        SMTP.Credentials = New System.Net.NetworkCredential("Gmail account", "Gmail password")
        SMTP.Send(EmailMessage)
    Catch ex As Exception
    End Try
End Sub

End Class

Source: http://whydomy.com/2012/09/14/visual-basic-2010-send-an-email/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.