IT Community - Software Programming, Web Development and Technical Support

How to send email in VB.NET 2005(From Windows Applications)

This is a discussion on How to send email in VB.NET 2005(From Windows Applications) within the VB.NET Programming forums, part of the Software Development category; How to send email in from VB.NET(2005) in Windows application. I have tried with the following code. But ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > VB.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 02-21-2008, 10:48 PM
psivakumarmca81 psivakumarmca81 is offline
D-Web Trainee
 
Join Date: Feb 2008
Posts: 4
psivakumarmca81 is on a distinguished road
Default How to send email in VB.NET 2005(From Windows Applications)

How to send email in from VB.NET(2005) in Windows application.
I have tried with the following code. But i am unable to send.


Imports System.Web.Mail

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myMessage As System.Web.Mail.MailMessage
Try
myMessage = New System.Web.Mail.MailMessage
With myMessage
.To = "abc@xyz.co.in"
.From = "abc@xyz.co.in"
.Subject = "Testing Mail "
.Body = "This is a testing mail without attachments"
.BodyFormat = System.Web.Mail.MailFormat.Html
End With
System.Web.Mail.SmtpMail.SmtpServer = "smtp.servername.com"
System.Web.Mail.SmtpMail.Send(myMessage)

Catch myexp As Exception
MsgBox(myexp.Message, MsgBoxStyle.Critical, Me.Text)
End Try
End Sub

But it shows the error.

"The server rejected one or more recipient addresses. The server response was: 553 sorry, Authentication failed or timed out. Please do get messages first to authenticate yourself.(#4.4.3)".

But the above code has successfully executed before 2 months.Now it is not.I don't know where the problem has occured. We are using the smtp server. Please help.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-22-2008, 09:13 PM
Balasubramanian.S Balasubramanian.S is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 181
Balasubramanian.S is on a distinguished road
Default Re: How to send email in VB.NET 2005(From Windows Applications)

Hi,

Use this code to send mail.

Dim myMessage As System.Web.Mail.MailMessage
Try
myMessage = New System.Web.Mail.MailMessage
With myMessage
.To = "abc@xyz.co.in"
.From = "abc@xyz.co.in"
.Subject = "Testing Mail "
.Body = "This is a testing mail without attachments"
.BodyFormat = System.Web.Mail.MailFormat.Html
End With
System.Web.Mail.SmtpMail.Send(myMessage)

Catch myexp As Exception
MsgBox(myexp.Message, MsgBoxStyle.Critical, Me.Text)
End Try
__________________
S.Balasubramanian
Nothing is impossible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-24-2008, 06:20 PM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,321
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up Re: How to send email in VB.NET 2005(From Windows Applications)

Hi Siva,

I think it the problem with the SMTP server Authentication Credential.

SO try this part with you code.

Create an object for the class SMTPClient, another object for network credential, assign the user name and password of a mail address. map that credential to the SMTP client.

It will fix your problem.

Code:
Public Sub SendMail()
Dim strTo As String = frmMain.txtTo.Text
Dim strFrom As String = frmMain.txtFrom.Text
Dim strSubject As String = frmMain.txtSubject.Text
Dim strBody As String = frmMain.txtBody.Text
Dim mailMessage As New System.Net.Mail.MailMessage(strFrom, strTo,
strSubject, strBody)
Dim mailClient As New
System.Net.Mail.SmtpClient("IpAddressOfMyExchangeServer", 25)

mailClient.Credentials = New
NetworkCredential("IpAddressOfMyExchangeServer\UserName", "Password")
mailClient.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network

Try
mailClient.Send(mailMessage)
Catch ex As Exception
frmMain.txtInfo.Text = ex.ToString
Exit Sub
End Try

frmMain.txtInfo.Text = "Your message was sucessfully sent."
End Sub

The above code works fine.

Hope useful...
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/vb-net-programming/5308-how-send-email-vb-net-2005-windows-applications.html
Posted By For Type Date
DiscussWeb IT Community - Technical Support and Technology Discussions This thread Refback 02-22-2008 12:37 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to send email in VB.NET 2005(From Windows Applications) psivakumarmca81 Discussweb HQ 2 02-22-2008 07:33 PM
Practical issues when we develop code in Windows Forms in C#.Net 2005 Sathish Kumar C# Programming 10 09-20-2007 06:17 AM
Email Send Using MYSQL or Oracle sivaramakrishnan Database Support 1 08-08-2007 02:39 AM
How to convert a SMS message in to Email in Windows mobile? theone Mobile Software Development 1 07-24-2007 10:41 PM
How to Send Email from a PHP Script Using SMTP Authentication? Sabari PHP Programming 1 07-20-2007 04:42 AM


All times are GMT -7. The time now is 02:05 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0