Solved

Problems sending Mail in ASP.NET

Posted on 2009-03-30
9
372 Views
Last Modified: 2013-11-30
I have set up my local SMTP Server to allow relaying to 127.0.0.1 and I have even opened up Port 25 and yet I cannot get mail to send out on my Windwos XP 64-Pit Pro computer.  All of the messages drop into the Pickup folder and then are moved to the Queue folder - where they sit forever.

The messages get to the SMTP server without any issues but they never leave - any ideas?
0
Comment
Question by:ktola
  • 5
  • 4
9 Comments
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 24025936
is your SMTP Services running and configured correctly?

is the sendusing property set correctly as 1 ?
0
 

Author Comment

by:ktola
ID: 24028492
There is no such option when using the System.Net.Mail class in the .NET 3.5 framework.  I am using the default credentials as follows:
SmtpClient thisClient = new SmtpClient();
thisClient.UseDefaultCredentials = true;
thisClient.Send(thisMessage);
 
<system.net>
    <mailSettings>
      <smtp from="email@address.com">
        <network host="localhost" port="25" password="" userName="" />
      </smtp>
    </mailSettings>
  </system.net>

Open in new window

0
 

Author Comment

by:ktola
ID: 24029016
I have been doing some further testing and I wonder if the fact that I have a multi-homed computer is causing the issues.  When I looked at the properties of the SMTP Server, I noticed that it was reading all three of my network connection - 192.168.1.4, 10,10,90.1 and 10.10.90.4 (I run private connections for database and storage...).
Since the 192 address is the one pointing to the Internet, I enabled that IP to relay but that did not correct the issue - but now I am wondering if this is along the lines of the problem...
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 50

Expert Comment

by:Ryan Chong
ID: 24029606
is the port 25 opened?

I'm something like this to send out emails in .NET Framework 3.5:
using System.Net.Mail;
 
//...
 
public static Boolean sendMail(String SenderName, String SenderEmail, String ReceiverName, String ReceiverEmail, String Subject, String Body, Boolean isHTML, String SMTPHost, int SMTPPort, Boolean isAuthenticationNeeded, String SMTPUserName, String SMTPUserPwd)
        {
            try
            {
                SmtpClient sclient = new SmtpClient(SMTPHost, SMTPPort);
                sclient.DeliveryMethod = SmtpDeliveryMethod.Network;
                if (isAuthenticationNeeded)
                {
                    sclient.Credentials = new System.Net.NetworkCredential(SMTPUserName, SMTPUserPwd);
                }
 
                MailMessage mail = new MailMessage();
                mail.Subject = Subject;
                mail.IsBodyHtml = isHTML;
                mail.Body = Body;
                mail.BodyEncoding = System.Text.Encoding.UTF8;
                if (SenderName == "")
                {
                    mail.From = new MailAddress(SenderEmail);
                }
                else
                {
                    mail.From = new MailAddress(SenderEmail, SenderName);
                }
                mail.SubjectEncoding = System.Text.Encoding.UTF8;
                if (ReceiverName == "")
                {
                    mail.To.Add(ReceiverEmail);
                }
                else
                {
                    mail.To.Add(new MailAddress(ReceiverEmail, ReceiverName));
                }
                sclient.Send(mail);
                return true;
            }
            catch (SmtpException)
            {
                return false;
            }
            catch (Exception)
            {
                return false;
            }       
        }

Open in new window

0
 

Author Comment

by:ktola
ID: 24030011
Thank you for the code - I am already using most of those settings.  You can actually set most of those in the web.config file and then use the UseDefaultCredentials option when setting up the SmtpClient - this makes it easier to deploy solutions.
The messages are getting to the SMTP Server but being queued immediately and never transmitting.  My experience suggests that this is a relay issue with the SMTP server but I cannot figure out how to overcome the limitation.  I have no enabled the entire 10,, 192, and 127. subnets to relay and that STILL is not working...
I also do have Port 25 open
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 24035330
I'm not that familiar with subnets/relay things.... or do you have a chance to use external SMTP host to send out emails?
0
 

Author Comment

by:ktola
ID: 24035373
I am using the same settings that I use to successfully send out emails on numerous Windows 2003 servers (all using a local SMTP server).  The essence of the settings are to enable relaying for the IP of interest, set the SMTP server to that same IP address and Port 80 and then point the web.config host to that IP address.
On Windows Server 2003 (and 2000), everything works fine - on Windows XP 64-BIt Pro, the email stay in the queue forever...
0
 

Accepted Solution

by:
ktola earned 0 total points
ID: 24188117
For those people who are interested, I finally figured out my issues - here is how to configure IIS and your ASP.NET website:
SMTP Server Settings (i.e. Right-Click on SMTP Server in IIS and select Properties):
  1. Select the Default IP for the Server on the main tab
    1. This is usually the same as the IP Address of the main website
    2. Click on the Advanced button and make sure/change the port to 25
  2. Click on the Relay tab
    1. Click on Authentication and ensure that only Anonymous Access is checked
    2. Click on Connection and ensure that the All Except List Below is selected
    3. Click on Relay and Ensure that the Only The List Below option is selected
      1. Add both 127.0.0.1 and your Default IP Address to the list
  3. Close The SMTP Window
Go into your Web.Config file and make sure you add the following section:

<system.net>
     <mailSettings>
          <smtp from=YourEmail@Email.com>
               <network host="DEFAULT IP ADDRESS" password="" userName=""/>
          </smtp>
     </mailSettings>
</system.net>
The DEFAULT IP ADDRESS should equal the IP Address that you select in Step #1 above.
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 24190137
thanks for the sharing, cheers!
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is Usenet? There are many different opinions on exactly what Usenet is an isn't. Many opinions are incorrect simply out of ignorance. The Wikipedia listing about Usenet does a good job of explaining it, so instead of repeating it all here I wi…
When you’re making plans to join the modern business race, you should analyze various details that may affect your results. Nowadays, millions of businesses are trying to grow into established and appreciated professional enterprises.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question