View Single Post
  #3 (permalink)  
Old 02-24-2008, 07: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
Reply With Quote