Click here to Skip to main content
Click here to Skip to main content

Email and SMS Sending Through VB.NET for Free

By , 17 Nov 2009
 

Introduction

This VB.NET code sends Email and SMS for free with the help of your Gmail ID. One main advantage of this is that you can send SMS for free because most webservices are not free to use with your application.

Using the Code

I used Gmail as my SMTP server and Mytoday to support free SMS Service here in this code. Since this code uses Gmail SMTP server, you need a Gmail account to send Email. Actually SMS from the application is sent from the Email. You can send SMS only to particular numbers in India. When you register your phone number in the website http://email2sms.netcore.co.in/, an Email ID will be given for the phone number which you register, so that when you mail to that id the message will be received as SMS in the particular number. Suppose the phone number is 9897345890 the mail id given from that website will be like this 9897345890@m3m.in. It works only for Indian numbers.

To run this application successfully, two things should be done:

  1. You must have Gmail ID.
  2. Register the phone number which you are going to use in a website http://email2sms.netcore.co.in/.
Private Sub Button1_Click(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles Button1.Click

Dim smtpServer As New SmtpClient()
Dim mail As New MailMessage
smtpServer.Credentials = New Net.NetworkCredential_
	(TextBox1.Text & "@gmail.com", TextBox2.Text)
smtpServer.Port = 587
smtpServer.Host = "smtp.gmail.com"
smtpServer.EnableSsl = True
mail.From = New MailAddress(TextBox1.Text & "@gmail.com")
If RadioButton1.Checked = True Then
mail.To.Add("91" & TextBox3.Text & "@m3m.in")
ElseIf RadioButton2.Checked = True Then
mail.To.Add(TextBox3.Text)
End If
mail.Subject = TextBox4.Text
mail.Body = TextBox5.Text()
smtpServer.Send(mail)
MsgBox("mail is sent", MsgBoxStyle.OkOnly, "Report")
End Sub

Hope this code will be helpful...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

balaji2525
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionexception [modified]memberBalakrishnan B23 Mar '13 - 4:26 
hello im getting an exception for that
smtpServer.Send(mail)
its showing as an error
can any 1 pls help me.....?
its urgent pls.....

modified 23 Mar '13 - 23:57.

QuestionHelp!!memberGopal Krishna Mailapalli12 Jan '13 - 23:17 
I am a beginner,, Frown | :(
Want to create a sms sending visual basic application through way2sms.com or fullonsms.com??
Thumbs Up | :thumbsup:
tell all the procedure step wise?? along with design of the form!!
QuestionHow can we use this code for srilankan customers....please urgentmemberMember 434691614 Nov '12 - 22:11 
How can we use this code for srilankan customers....please urgent
QuestionSending SMS using vb.netmemberRakesh A Rao1 Oct '12 - 21:22 
Hey Guys...
 
How can I use way2sms.com in place of m3m.com....
 
Plz help me out with this..
QuestionREG:projectmembermohanjack13 Sep '12 - 20:49 
sir:-
i can.t send sms please tell me instruction sir Smile | :) Smile | :) Smile | :) Smile | :) Smile | :) Smile | :)
AnswerRe: REG:projectmemberbalaji252513 Sep '12 - 20:53 
please check my reply to "sarode_sanket"
Questionquestionmembersarode_sanket29 Jul '12 - 20:05 
Hello there,
I have tried this snippet for my gmail account and it works.
I have send the sms to my mobile, i am not getting the message. Sms is not working.
Please give some suggestions to work on it.
with regards,
sanket
AnswerRe: questionmemberbalaji252529 Jul '12 - 21:38 
It has been very long since i posted this, I dono whether it works or not. But let me tell what i did actually, Mostly no one provide free sms service api but the sites like 160by2 offer mail intimation services for free. have an account from way2sms, then you will be provided with an mail address for your mobile number. fill your sms contents in subject field of mail and send to mobile's mail address(****@way2sms.com)you should receive it as an sms.
QuestionThis is not working Please send me the code using visual studio 2008 for my mail soonmemberyuganthi16 Jul '12 - 7:18 
Pls send the mail for this
AnswerRe: This is not working Please send me the code using visual studio 2008 for my mail soonmemberbalaji252516 Jul '12 - 19:21 
pls refer http://vb.net-informations.com/communications/vb.net_smtp_mail.htm
GeneralRe: This is not working Please send me the code using visual studio 2008 for my mail soonmemberyuganthi16 Jul '12 - 22:46 
okay i ll see this link and let you know how is it?
GeneralPlease help me the programming of my program SMS amd Mailmemberjaber-omar16 Apr '12 - 1:35 
<code><code></code></code><b>This program has a service online of SMS and Email ok.
I and I do not know how to deal with SMS and email
Please help me . i need the cod of vb.net
www.jaber.sae@hotmail.com</b>
<a href="http://www14.0zz0.com/2012/04/16/11/649521885.jpg">http://www14.0zz0.com/2012/04/16/11/649521885.jpg</a>[<a href="http://www14.0zz0.com/2012/04/16/11/649521885.jpg" target="_blank" title="New Window">^</a>]
[url=http://www.0zz0.com][img]http://www14.0zz0.com/2012/04/16/11/649521885.jpg[/img][/url]
<a href="http://www14.0zz0.com/2012/04/16/11/819611943.jpg">http://www14.0zz0.com/2012/04/16/11/819611943.jpg</a>[<a href="http://www14.0zz0.com/2012/04/16/11/819611943.jpg" target="_blank" title="New Window">^</a>]
<a href="http://www14.0zz0.com/2012/04/16/11/819611943.jpg">http://www14.0zz0.com/2012/04/16/11/819611943.jpg</a>[<a href="http://www14.0zz0.com/2012/04/16/11/819611943.jpg" target="_blank" title="New Window">^</a>]
Questionsending email failedmemberMember 769909024 Sep '11 - 6:14 
hai... when i used this code with try catch ........ it was responding exception message as "failure sending message"..... how to solve this......... pls help me
GeneralAny idea of sending sms without using the 3rd part (m3m) registration.memberDineshSIS22 Aug '10 - 23:15 
Hi Balaji,
 
Any idea of sending sms without using the 3rd party (m3m) registration.
is there any thing like sending to email to mobile number and recieving it as sms ...
i searched and found few samples like 98401xxxxx@airtelchennai.com which doesnt work.
is there any working sample that you have used ?
GeneralRe: Any idea of sending sms without using the 3rd part (m3m) registration.memberbalaji252525 Aug '10 - 15:56 
hi, like you said "98401xxxxx@airtelchennai.com " like those stuff never works. it is about free sms thats why it is neccessary to register and also has limitations. if you need it without registeration then you should buy bulk sms from some website.
GeneralRe: Any idea of sending sms without using the 3rd part (m3m) registration.memberbalaji252525 Aug '10 - 16:03 
when you register in 160by2.com they providing a facilty to read your mail as sms when they reach ur 160by2 id. you can refer that website too it is better than m3m registration.
Questionwhat about israel ?memberBEDEK336 Mar '10 - 3:37 
hello.
 

he code is good.
 
about sms - what is the suitible code to
send free sms in israel...
 
mail.To.Add("+972" & TextBox3.Text & "@m3m.ie")
 

i meed to change the code above.
 

please let me know...
 
thank you
GeneralMy vote of 2memberVamsi Pulavarthi15 Dec '09 - 5:44 
Not a bad article but I agree with the others. The article could have been better.
 
Balaji - To answer how... here are some of my ideas
1. Could have made the email, port, server etc configurable so other mail servers could be used
2. Add the functionality to send SMS to any country. Not just India
GeneralMy vote of 1mvpAshfield18 Nov '09 - 5:19 
So its really a poorly coded example of sending email via gmail. Its not really sending sms at all, is it?
Generalcalculator in vbmembersura94516 Nov '09 - 1:53 
hi i have an assignment on caculator program in vb with function to thuseday so please help me
GeneralRe: calculator in vbmemberbalaji252517 Nov '09 - 7:12 
u need calculator prog but i didnt understand "function to thuseday "...
GeneralMy vote of 1memberGriffinPeter13 Nov '09 - 8:21 
A very poor code dump.. no suprises.
GeneralRe: My vote of 1memberbalaji252517 Nov '09 - 7:03 
do u have any better idea on this topic...
GeneralRe: My vote of 1memberbalaji252517 Nov '09 - 7:06 
if u ve any better idea on this topic just tell me....
Generalpls helpmembermhn2179 Nov '09 - 0:25 
I'm getting this exception while trying to send an email using my gmail credentials.
 
FYI : My pc is behind a proxy.
 
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
 
************** Exception Text **************
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 74.125.155.109:587
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
--- End of inner exception stack trace ---
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at Email.Form1.Button1_Click(Object sender, EventArgs e) in D:\studies\my proj\Email\Email\Form1.vb:line 18
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
 

************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Email
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///E:/dotnet/Email%20and%20sms/Email/Email/bin/Debug/Email.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
 
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
 
For example:
 
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
 
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 17 Nov 2009
Article Copyright 2009 by balaji2525
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid