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 }


LinkBack URL
About LinkBacks
Reply With Quote
