In this article I am going to show how to send mail from Gmail or Yahoo using VB.Net & C# without logging into your Gmail account.
SMTP Client
- Yahoo: smtp.mail.yahoo.com
- Gmail: smtp.gmail.com
VB.NET Code
Imports System.Net
Public Class Form1
Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
txtatt.Text = OpenFileDialog1.FileName.ToString
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String = ""
Dim state As Boolean
If Microsoft.VisualBasic.Right(txtfrom.Text, 9) = "gmail.com" Then
str = "smtp.gmail.com"
state = True
ElseIf Microsoft.VisualBasic.Right(txtfrom.Text, 9) = "yahoo.com" Then
str = "smtp.mail.yahoo.com"
state = False
End If
Dim From As Mail.MailAddress = New Mail.MailAddress(txtfrom.Text)
Dim [To] As Mail.MailAddress = New Mail.MailAddress(txtto.Text)
Dim Message As Mail.MailMessage = New Mail.MailMessage(From, [To])
Message.Subject = txtsub.Text
Message.Body = txtmess.Text
Message.Attachments.Add(New Mail.Attachment(OpenFileDialog1.FileName.ToString))
Dim client = New Mail.SmtpClient(str)
client.EnableSsl = state
client.Credentials = New System.Net.NetworkCredential(txtfrom.Text, txtpass.Text)
client.Send(Message)
MsgBox("Send Email Successfully")
End Sub
End Class
C#.NET Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

maharaja sPosted Sep 8, 2015, 6:03 AM
no it is not working and shows above msg
maharaja sPosted Sep 8, 2015, 6:03 AM
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Authentication required
maharaja sPosted Sep 8, 2015, 6:03 AM
no it is working
brgiht cbnPosted Mar 2, 2015, 10:18 AM
please i'm getting failure sending mail
Pratham JaiswalPosted Aug 31, 2014, 7:06 AM
I have got the following error for Yahoo login: "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Authentication required".. Please help me..
Pratham JaiswalPosted Aug 31, 2014, 6:46 AM
I have got the following error: "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at"
yohanes sukardiPosted Jan 7, 2014, 6:24 AM
THANKS U very much....
Deeapk KaushikPosted May 16, 2013, 3:49 AM
Nice article, Thanks for sharing
shwetank suthareditedPosted Apr 3, 2013, 6:53 AMEdited Apr 3, 2013, 6:53 AM
Error in Yahoo . I can't send mail from Yahoo
Tina GargPosted Oct 22, 2012, 12:24 AM
Wow that a very nice article, Thanks for sharing.......
Nishant RoyPosted Oct 21, 2012, 10:57 PM
Thanks for sharing this nice article.