Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want tot send mail to vjcet@vjcet.org from my site in asp.net c#.
how to do it ,my code is working foe some mail but faild in vjcet@vjcet.org.
any one please help me.


my code is .

protected void Button1_Click(object sender, EventArgs e)
XML
{
    SmtpClient client = new SmtpClient();
    MailMessage mail1 = new MailMessage();

    try
    {
        DataSet ds = new DataSet();


        ds.ReadXml(Server.MapPath("~/Admin/xml/feedbackmail.xml"));
        string ToAddress = ds.Tables[0].Rows[0][0].ToString();
        //mail1.To = ds.Tables[0].Rows[0][0].ToString();
        mail1.To.Add(new MailAddress(ToAddress));
        mail1.From = new MailAddress(txtEmail.Text);



        mail1.Body = "Sender : " + txtEmail.Text + "\n" + "Name : " + txtname.Text + "\n" + "Street Address : " + txtStreet.Text + "\n" + "City:" + txtCity.Text + "\n" + "State:" + txtState.Text
            + "\n" + "Zip Code:" + txtZip.Text + "\n" + "Country:" + txtCountry.Text + "\n" + "Telephone:" + txtTelephone.Text + "\n" + "Fax:" + txtFax.Text + "\n" + "\n" + "Comments:" + txtComments.Text;
        //SmtpMail.SmtpServer.Insert(0, "83.245.63.194");
        //SmtpMail.Send(mail1);
        client.Send(mail1);

        ClearContents();
        // ClientScript.RegisterClientScriptBlock(typeof(Button), "OnClick", "<script language=javascript>alert('Message Send');</script>"); ;
       // ClientScript.RegisterClientScriptBlock(typeof(Button), "OnClick", "<script language=javascript>alert('');</script>"); ;
        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Mahir", "<script type='text/javascript'>alert('Message has been Send Successfully');</script>", false);
    }
    catch (Exception ex)
    {
        // ClientScript.RegisterClientScriptBlock(typeof(Button), "OnClick", "<script language=javascript>alert('Message Send Failed');</script>");
       // ClientScript.RegisterClientScriptBlock(typeof(Button), "OnClick", "<script language=javascript>alert('Message Send Failed');</script>");
        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Mahir", "<script type='text/javascript'>alert('Message Send Failed');</script>", false);
    }

}
Posted
Updated 7-May-12 21:11pm

Without your code, we can't be specific.
However, try comparing it to this: Sending an Email in C# with or without attachments: generic routine.[^]

(I would have just asked for teh code, but the comments/queries facility is down at the moment.)
 
Share this answer
 
Comments
Monjurul Habib 8-May-12 16:34pm    
5!
There are many ways to send mail simple way is using smtp client you can send mails and your problem is your domain is not recognized by host domain means your from address domain.If you using mailserver03 to configure domain mail means you will find one option that enable your domain other wise try to do this ( ssl security=false) in program
 
Share this answer
 
C#
public void sendmail()
    {

        MailMessage msg = new MailMessage();
        msg.From = new MailAddress("aru44.ece@gmail.com");

        msg.To.Add("siva@y.com");

        msg.Subject = "Record inserted";

        msg.Body = "The record has been added";

        System.Net.Mail.SmtpClient smtp = new SmtpClient("smtp.shriramvalue.com");

        smtp.Send(msg);

        //SmtpClient smt = new SmtpClient("smtp.gmail.com");

         //SmtpClient client = new SmtpClient();
         //client.Host = "smtp.com"; 
         //client.Port = 25;

         //client.Send(msg);
              Response.Write("Mail Successfully sent");


    }
 
Share this answer
 
Try this one

C#
try
        {
            string mailBody = String.Empty;
            
            System.Net.Mail.MailMessage objMessage = new System.Net.Mail.MailMessage();
            objMessage.IsBodyHtml = true;
            objMessage.Subject = "Issue Response Details";
            objMessage.Body = "your message";
            //objMessage.To.Add(objMailerCollectionView.TOMAILID);
            //Checking From Mail address from appsettings
              // hardcoding values for testing purpose

            
            objMessage.To.Add("toemailid");
            objMessage.From = new MailAddress("fromemailid");
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
            // This statement will give the valid remote certificate according to the validation procedure to send mail. Otherwise it will not send a mail
            ServicePointManager.ServerCertificateValidationCallback = delegate(object s, System.Security.Cryptography.X509Certificates.X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
            smtp.Send(objMessage);
        }
        catch (Exception ex)
        {
            throw ex;
        }
 
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