?
Solved

Problems sending Mail in ASP.NET

Posted on 2009-03-30
9
Medium Priority
?
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 53

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
Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

 
LVL 53

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 53

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 53

Expert Comment

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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

762 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