Can Not Send Email
Can Not Send Email
Can Not Send Email
Can Not Send Email
Can Not Send Email
Can Not Send Email Can Not Send Email Can Not Send Email Can Not Send Email Can Not Send Email Can Not Send Email Can Not Send Email Can Not Send Email
Can Not Send Email Can Not Send Email
Can Not Send Email
Go Back  Xtreme Visual Basic Talk > > > Can Not Send Email


Reply
 
Thread Tools Display Modes
  #1  
Old 11-13-2009, 12:34 AM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default Can Not Send Email


Hello,
I have a problem sending an email using System.Net.Mail namespace. I've read a lot and everytime I solve a problem I face anothor one. I really do not want to say this but, because I googled a lot and failed to solve every problem, please I need someone to help me without directing me to external links, if possible (I read many articles and no one worked for me... every time I got a different error).

=================
What I do is:
  1. Create a new Web Site in Visual Studio 2008
  2. Add a button to the Deafult.aspx Page
  3. At the top of the Default.aspx.vb, I import the following namespace:
    Code:
    Imports System.Net.Mail
  4. In the Click event for the button, I write:
    Code:
            Dim message As New MailMessage("thefarnight@yahoo.com", "alawfiadel@hotmail.com", _
                                           "Hi", "Hi... This is test")
            Dim client As New SmtpClient("localhost", 25)
            client.UseDefaultCredentials = True
            client.Send(message)
  5. When testing the page, I get this error:
    Error: Failure sending mail
    Inner Exception 1: Unable to connect to the remote server
    Inner Exception 2: No connection could be made because the target machine actively refused it <**ipaddress**>:25

Please Note:
  • My operating system is Windows XP Professional
  • The firewall is turned OFF
  • The ASP.NET Development Server is running my site on (localhost:4689). When I tried using this port in the SmtpClient, I got this error:
    Error: Failure sending mail
    Inner Exception: Smtp server returned an invalid response
  • When I used the command 'telnet localhost 25' in the Command Prompt, it could not connect. But when I used 'telnet localhost 4689' it connected.
  • Both FromEmail and ToEmail are mine, and they are valid
What am I doing wrong?

Thank you.

Adel,
Reply With Quote
  #2  
Old 11-13-2009, 04:07 AM
Merrion's Avatar
MerrionCan Not Send Email Merrion is offline
Ultimate Contributor

* Guru *
 
Join Date: Sep 2001
Location: Dublin, Ireland
Posts: 1,828
Default

Impossible to tell what is causing it but have you tried putting your smtp settings in the application.config file?

e.g.
Code:
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network
          host="localhost"
          port="25"
          defaultCredentials="true"
        />
      </smtp>
    </mailSettings>
  </system.net>
This, at least, would allow you to experiment withour recompiling the app each time...
Reply With Quote
  #3  
Old 11-13-2009, 09:11 AM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

Thank you, Merrion.
I tried putting the setting in the web.config as you mentioned. It gave me the same error as putting it in code.

Please help me.

Adel,
Reply With Quote
  #4  
Old 11-13-2009, 11:12 AM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

I have solved the problem by setting a real SMTP server (I used gmail server).

Thank you...
Adel,
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Can Not Send Email
Can Not Send Email
Can Not Send Email Can Not Send Email
Can Not Send Email
Can Not Send Email
Can Not Send Email Can Not Send Email Can Not Send Email Can Not Send Email Can Not Send Email Can Not Send Email Can Not Send Email
Can Not Send Email
Can Not Send Email
 
Can Not Send Email
Can Not Send Email
 
-->