Solved

Problems sending Mail in ASP.NET

Posted on 2009-03-30
9
369 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 49

Expert Comment

by:Ryan Chong
Comment Utility
is your SMTP Services running and configured correctly?

is the sendusing property set correctly as 1 ?
0
 

Author Comment

by:ktola
Comment Utility
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
Comment Utility
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
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:ktola
Comment Utility
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 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
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
Comment Utility
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 49

Expert Comment

by:Ryan Chong
Comment Utility
thanks for the sharing, cheers!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now