Sending a Form using C# and ASP.net

alphaq44

New Member
Messages
1
Reaction score
0
Points
0
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
}
 

Hue Kares

New Member
Messages
38
Reaction score
6
Points
0
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.
 
Top