System.Web.Mail works fine but System.Net.Mail won't send email  
Author Message
EBots





PostPosted: .NET Framework Networking and Communication, System.Web.Mail works fine but System.Net.Mail won't send email Top

Hi, I am updating an existing VB.NET 1.1 app to 2.0. The existing app uses the System.Web.Mail namespace to send emails and it works fine, but when I try to update to use the System.Net.Mail namespace it stops working. Has anybody any ideas why

The following is the existing code that works:

Dim msg As New System.Web.Mail.MailMessage

msg.From =

msg.To =

msg.Subject = "Subject"

msg.Body = "Body"

System.Web.Mail.SmtpMail.SmtpServer.Insert(0, "<<SMTPServerName>>")

System.Web.Mail.SmtpMail.Send(msg)

I've changed the code to the following:

Dim client As New System.Net.Mail.SmtpClient("<<SMTPServerName>>")

Dim msg As New System.Net.Mail.MailMessage( , , "Subject", "Body")

client.Send(msg)

Your message did not reach some or all of the intended recipients.

Subject: Subject

Sent: 13/10/2006 10:39

The following recipient(s) could not be reached:

The recipient name is not recognized

I can't understand why it worked using the Web namespace but not the Net namespace. Any advice would be gratefully accepted.



.NET Development32  
 
 
AndrewBadera





PostPosted: .NET Framework Networking and Communication, System.Web.Mail works fine but System.Net.Mail won't send email Top

http://msdn2.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx

I believe you need to pass in MailAddress addresses, not strings ...


 
 
EBots





PostPosted: .NET Framework Networking and Communication, System.Web.Mail works fine but System.Net.Mail won't send email Top

Changing the code to the following makes no difference:

Dim client As New System.Net.Mail.SmtpClient("<<SMTPServerName>>")

Dim msg As New System.Net.Mail.MailMessage(New MailAddress(" ), New MailAddress( ))

msg.Subject = "Subject"

msg.Body = "Body"

client.Send(msg)

 


 
 
AndrewBadera





PostPosted: .NET Framework Networking and Communication, System.Web.Mail works fine but System.Net.Mail won't send email Top

have you tried sending asynchronously instead also, might not hurt to set the subject and body encoding ...
 
 
EBots





PostPosted: .NET Framework Networking and Communication, System.Web.Mail works fine but System.Net.Mail won't send email Top

I've tried setting body and subject encoding to UTF8 and also sending asynchronously but still the same result.
 
 
AndrewBadera





PostPosted: .NET Framework Networking and Communication, System.Web.Mail works fine but System.Net.Mail won't send email Top

I've tried setting body and subject encoding to UTF8 and also sending asynchronously but still the same result.

and when you send it async, you're wiring up the async completed callback

approximately how long does it take from start of send, or start of async send, to get an error reply


 
 
EBots





PostPosted: .NET Framework Networking and Communication, System.Web.Mail works fine but System.Net.Mail won't send email Top

Yep the callback function gets called within about 3 seconds of the call to SendAsync. I receive the error email from System Administrator in about the same amount of time too, using either Send or SendAsync.


 
 
AndrewBadera





PostPosted: .NET Framework Networking and Communication, System.Web.Mail works fine but System.Net.Mail won't send email Top

Yep the callback function gets called within about 3 seconds of the call to SendAsync. I receive the error email from System Administrator in about the same amount of time too, using either Send or SendAsync.

sorry, not sure what to tell you at this point.


 
 
eppyjerk





PostPosted: .NET Framework Networking and Communication, System.Web.Mail works fine but System.Net.Mail won't send email Top

Did you ever figure this one out
 
 
EBots





PostPosted: .NET Framework Networking and Communication, System.Web.Mail works fine but System.Net.Mail won't send email Top

Nope. I'm still using the 1.1 objects in a 2.0 application.
 
 
ahmedilyas





PostPosted: .NET Framework Networking and Communication, System.Web.Mail works fine but System.Net.Mail won't send email Top

take a look at this:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=616274&SiteID=1

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=724365&SiteID=1

your SMTPClient class needs to have:

  • SMTP Server address

  • SMTP Server port (Default SMTP ports are 25, which you still need to specify)

    As well as this, you need to pass credentials if the SMTP Server requires it.

    Do you get any errors if so - what are they



  •  
     
    JonGallant





    PostPosted: .NET Framework Networking and Communication, System.Web.Mail works fine but System.Net.Mail won't send email Top

    This issue has been resolved in .NET 2.0 SP1. See this blog post for more info:

    http://blogs.msdn.com/jongallant/archive/2007/12/07/system-net-mail-mailmessage-mail-header-casing-issue-fixed-in-net-2-0-sp1-net-3-5.aspx