+ Reply to Thread
Results 1 to 2 of 2

Thread: Sending a Form using C# and ASP.net

  1. #1
    alphaq44 is offline x10Hosting Member alphaq44 is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    1

    Sending a Form using C# and ASP.net

    Hi, I am having trouble with trying to send a form using C# on x10hosting.com. I have tested it out on my local machine and it works fine, but when I upload it to the website it does not work. Does x10 hosting support sending email to a gmail account using ASP.net or am I just doing it wrong? Here is my code :
    Code:
     using System.Web.Mail;
    using System;
    
    
    public partial class _Default : System.Web.UI.Page 
    {
        #region  "Send email"
    // when button is clicked it performs this action 
    
        protected void btnSendmail_Click(object sender, EventArgs e)
        {
            
           
            try
            {
                System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage();
            myMail.Fields.Add
    //smtp server 
                ("http://schemas.microsoft.com/cdo/configuration/smtpserver",
                              "smtp.gmail.com");
    
    //gmail port number 
            myMail.Fields.Add
                ("http://schemas.microsoft.com/cdo/configuration/smtpserverport",
                              "587");
            myMail.Fields.Add
                ("http://schemas.microsoft.com/cdo/configuration/sendusing",
                              "2");
            //sendusing: cdoSendUsingPort, value 2, for sending the message using 
            //the network.
    
            //smtpauthenticate: Specifies the mechanism used when authenticating 
            //to an SMTP 
            //service over the network. Possible values are:
            //- cdoAnonymous, value 0. Do not authenticate.
            //- cdoBasic, value 1. Use basic clear-text authentication. 
            //When using this option you have to provide the user name and password 
            //through the sendusername and sendpassword fields.
            //- cdoNTLM, value 2. The current process security context is used to 
            // authenticate with the service.
    
    // authenticate equals 1 
    
            myMail.Fields.Add
            ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");
            //Use 0 for anonymous
    
            myMail.Fields.Add
            ("http://schemas.microsoft.com/cdo/configuration/sendusername",
                "xxxxx");
    
            myMail.Fields.Add
            ("http://schemas.microsoft.com/cdo/configuration/sendpassword",
                 "xxxx");
    
            myMail.Fields.Add
            ("http://schemas.microsoft.com/cdo/configuration/smtpusessl",
                 "true");
    
            myMail.From = txtEmail.Text;
            myMail.To = "xxxx@gmail.com";
            myMail.Subject ="xxxxx";
           
            myMail.Body =  txtEmail.Text;
           
            System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com:587";
            System.Web.Mail.SmtpMail.Send(myMail);       
    
                lblStatus.Text = "Email successfully sent.";
            }
            catch (Exception ex)
            {
                //displays a error in a region when the message fails 
    
                lblStatus.Text = "Send Email Failed.<br>" + ex.Message;
            }
        }
        #endregion
    
    
    //reset button 
        #region "Reset"
        protected void btnReset_Click(object sender, EventArgs e)
        {
    //clears the email form 
            txtEmail.Text = "";
        }
        #endregion
    }

  2. #2
    Hue Kares's Avatar
    Hue Kares is offline x10Hosting Member Hue Kares is an unknown quantity at this point
    Join Date
    Feb 2009
    Location
    UK
    Posts
    38

    Re: Sending a Form using C# and ASP.net

    Hi alphaq, welcome to x10! What is the specific Exception Message you're getting?

    If your code worked at home, let's ignore it for now (I assume you added the comments for our benefit, as there is one misplaced within a line of code). So that leaves us with gmail. I don't use it myself, so bear in mind I'm guessing here:

    1/ Have you set up an MX record yet?

    You'll see 'MX Entry' in the 'Mail' section of your cPanel; use this link for info on what to do in there...

    There are other pages to help you over at Google Apps Admin Help, so go check them out. They note that it can take up to 48 hours for the MX record to change.

    2/ As you have set SSL authentication as True, you may try using port 465 instead.

    I hope this helps you; Good luck.

+ Reply to Thread

Similar Threads

  1. How to get ASP.Net to work at x10Hosting
    By Hue Kares in forum Tutorials
    Replies: 56
    Last Post: 11-11-2011, 01:09 PM
  2. ASP.NET Masterpage and javascript form validation
    By yannhuet in forum Programming Help
    Replies: 0
    Last Post: 08-19-2009, 05:21 AM
  3. ASP.NET contact form problem
    By yannhuet in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 08-17-2009, 10:58 PM
  4. ASP.NET contact form problem
    By yannhuet in forum Programming Help
    Replies: 0
    Last Post: 08-13-2009, 10:07 PM
  5. Sending email with ASP.NET in C#
    By wraithlunati in forum Free Hosting
    Replies: 0
    Last Post: 07-24-2009, 02:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers