Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:

My problem is SMTP Server (localhost) sends the email but it sits in the Queue folder.

So I see all my emails are in C:\Inetpub\mailroot\Queue

Any Ideas how can I resolve this ,i developed application using asp.net and c#

for sending email applications.i am using iis6.0,window 2008 r2,what r settings requried in smtp


my code is give below can i provide any setting under smtp?



C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Web.Mail;
using System.Configuration;

namespace Emailapp
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnclick_Click(object sender, EventArgs e)
        {

                     string strFrom=txtfrom .Text.Trim ();
                     string  strTo = txtTo.Text.Trim();
                     string strCc = txtCc.Text.Trim();
                    string strSubject = txtSubject.Text.Trim();
                    string strBody = txtbody .Text .Trim ();
            SendEmail(strFrom, strTo, strCc, strSubject, strBody);
        }

private void SendEmail(string strFrom, string strTo, string strCc, string strSubject, string strBody)
        {
            try
            {
                System.Net.Mail.SmtpClient  smtp = null;
                System.Net.Mail.MailMessage msg = null;
                smtp = new System.Net.Mail.SmtpClient("smtp.mydomain.com");
                                msg = new System.Net.Mail.MailMessage();
                msg.From = new System.Net.Mail.MailAddress(strFrom);


                #region To
                if (!string.IsNullOrEmpty(strTo.ToString().Trim()))
                {
                    string[] sTo = strTo.ToString().Split(';');
                    for (int i = 0; i < sTo.Length; i++)
                    {
                        if ((sTo[i].ToString().IndexOf('@') != -1) && (sTo[i].ToString().IndexOf('.') != -1))
                            msg.To.Add(new System.Net.Mail.MailAddress(sTo[i].ToString()));
                    }
                }
                #endregion To


                #region Cc
                if (!string.IsNullOrEmpty(strCc.ToString().Trim()))
                {
                    string[] sCc = strCc.ToString().Split(';');
                    for (int i = 0; i < sCc.Length; i++)
                    {
                        if ((sCc[i].ToString().IndexOf('@') != -1) && (sCc[i].ToString().IndexOf('.') != -1))
                            msg.CC.Add(new System.Net.Mail.MailAddress(sCc[i].ToString()));
                    }
                }
                #endregion Cc

                 msg.Subject = strSubject;
                msg.Body = strBody;
                msg.IsBodyHtml = true;
                smtp.Send(msg);
                //SmtpMail.Send(msg);
                 Response.Write("Your Email has been sent sucessfully");



            }
            catch (Exception ee)
            {
              Response .Write ("failour message"+ee.ToString ());
            }
            //catch (SmtpException smEx)
            //{
            //    throw new ArgumentException("Email sending failed with " + smEx.StatusCode.ToString());
            //}
        }
    }


        }
Posted
Updated 2-Jun-11 22:00pm
v4
Comments
ahmed_faramawi 2-Jun-11 10:33am    
i have the same problem

1 solution

I faced the same problem with Windows 2003 server. Ultimately I solved that. Can you please Post the ASP.NET sample code?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900