Click here to Skip to main content
15,904,817 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am converting the website from version 1.0 to 2.0.

In it there is a sending an email feature.

Previous namespace for sending email has changed.
I am adding a new namespace System.Net.Mail.MailMessage

For sending mail I got the failure sending smtp error.

What I do next:
Recently I installed windows server 2003 os.

My question: is it necessary to use smtp class and smtp server?
I want to check this operation locally, how to do?

My code is as follows. In this code the commented code is in version1.0 and without commented code in V2.0.
Please help me.

VB
' Dim mm As New System.Web.Mail.MailMessage()
Dim mm As New System.Net.Mail.MailMessage
' mm.To = toaccount
mm.To.Add(New MailAddress(toaccount))
' mm.From = fromaccount
mm.From = New MailAddress(fromaccount)

mm.Subject = title
mm.Body = matter
'mm.Priority = MailPriority.High
' mm.BodyFormat = MailFormat.Html
mm.IsBodyHtml = True
' System.Web.Mail.SmtpMail.SmtpServer = "192.168.1.100"
Dim SmtpMail As New SmtpClient()
'good SmtpMail.Host = "192.168.1.100"
'SmtpMail.Host = "localhost "
'Dim s As New SmtpClient("192.168.1.108")
Try
    'System.Web.Mail.SmtpMail.Send(mm)
    SmtpMail.Send(mm)
    ' System.Net.Mail.SmtpClient(mm)
    ' s.Send(mm)
    Response.Write("Mail is sent successfully")
Catch ex As Exception
    Response.Write("The fpllowing exception occurred :" + ex.ToString())
    'check the InnerException
    While Not (ex.InnerException Is Nothing)
        Response.Write("-----------------------")
        Response.Write("The following InnerException reported: " + ex.InnerException.ToString)
        ex = ex.InnerException
    End While
End Try
Posted
Updated 7-Sep-10 21:37pm
v5
Comments
Dalek Dave 8-Sep-10 3:37am    
Edited for Readability and Syntax.
Dylan Morley 8-Sep-10 5:35am    
Any additional details in your inner exception ?

You need to send the message to a SMTP server.

Usually these are mail servers or web servers with SMTP setup that you can relay messages through

Codeproject SMTP example
 
Share this answer
 
U need to assign smtp server name and port
Dim smtp As New SmtpClient(server, 25)
 
Share this answer
 
Configure SMTP Server locally and read my blog

jitendra-aspnet.blogspot.com/2009/10/sending-mail-in-aspnet.html
 
Share this answer
 
v2
Comments
Simon_Whale 8-Sep-10 11:25am    
edited link
The SMTP bunch of code should be like this:
VB
Dim smtpmail As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient("192.168.1.100", 25)
'If authentication needed then do this
Dim credential As New System.Net.NetworkCredential("User Name", "Password")
smtpmail.UseDefaultCredentials = False
smtpmail.Credentials = credential
'If authentication is not needed then
smtpmail.UseDefaultCredentials = True
'Now send the message
smtpmail.Send(mm)


Thanks.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900