Click here to Skip to main content
15,887,924 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my Code!!
i am using following namespace for sending mails,
System.Web.Mail; 
The mail has not been sent, any problem in my coding?
protected void btSend_Click(object sender, EventArgs e)
    {
        if (!(txtMymail.Text.Equals(string.Empty)) && !(txtRecivermail.Text.Equals(string.Empty)) && !(txtSubject.Text.Equals(string.Empty)) && !(txtBody.Text.Equals(string.Empty)))
        {
            //SmtpClient mailClient = new SmtpClient("smtp.gmail.com");
            string from = txtMymail.Text.ToString();
            string to = txtRecivermail.Text.ToString();
            string subject = txtSubject.Text.ToString();
            string body = txtBody.Text.ToString();
            System.Web.Mail.MailMessage mail12 = new System.Web.Mail.MailMessage();
            mail12.From =from;
            mail12.To = to;
            mail12.Subject = subject;
            mail12.Body = body;

            mail12.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.gmail.com");
            mail12.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 587);
            mail12.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2);
            mail12.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "vinoar@gmail.com");
            mail12.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "vinoth123");

            try
            {
                System.Web.Mail.SmtpMail.Send(mail12);
                //mailClient.Send(mail12);
            }
            catch (Exception exp)
            {
                lbErr.Visible = true;
                lbErr.ForeColor = Color.Red;
                lbErr.Text = "Error During Send mail" + exp.ToString();
            }
            lbErr.Visible = true;
            lbErr.ForeColor = Color.Blue;
            lbErr.Text = "Mail Send";
        }
        else
        {
            lbErr.Visible = true;
            lbErr.ForeColor = Color.Red;
            lbErr.Text = "Fill The Fields";
        }
    }
Posted
Updated 9-Dec-10 19:52pm
v3
Comments
TweakBird 10-Dec-10 0:57am    
code blocks fixed.
thatraja 10-Dec-10 1:53am    
Any error message? if yes then include in your question(always).

1 solution

Since you have not pointed what king of issue you are facing while sending emails:
It can be because of various reasons. You need to look at them one by one. Is the port open? Firewall permissions in place?
Further make sure you have configured SMTP configuration properly.
 
Share this answer
 
Comments
Vinoth Arun Raj. X 10-Dec-10 8:26am    
Hi

Thanks for the replay

i already used system.net.mail namespace , its working
but i use the system.web.mail it is not working

My main Task is Tracing Mails, and delivery Report also
Rob Branaghan 10-Dec-10 8:34am    
Another issue can be some servers only allow emails to go out if either the TO or FROM email address is one of theirs.

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