Jump to content

C# Coding To Send Email From Website.


Recommended Posts

BH

Hi, i've wrote a code to send email through the website. It works fine in Network Solutions hosting, but not in heliohost.org. My code is below. The form is located at http://www.crystalclear.heliohost.org/contactus.aspx. What could be causing it? Thanks so much.

using

 

 

System;

using

 

 

System.Collections.Generic;

using

 

 

System.Linq;

using

 

 

System.Web;

using

 

 

System.Web.UI;

using

 

 

System.Web.UI.WebControls;

using

 

 

System.Net.Mail;

namespace

 

 

WebApplication5

{

 

 

public partial class contactus : System.Web.UI.Page

{

 

 

protected void Page_Load(object sender, EventArgs e)

{

}

 

 

protected void Button1_Click(object sender, EventArgs e)

{

 

 

string bodystring = "Name: " + TextBox1.Text + " Email: " + TextBox2.Text + " Message: " + TextBox3.Text;

SendMail(TextBox2.Text, bodystring);

Response.Redirect(

 

"thankyou.aspx");

Response.Flush();

}

 

 

private void SendMail(string from, string body)

{

 

 

MailMessage message = new MailMessage("myemail@hotmail.com", "sendtoemail@hotmail.com", "Contact From Website", body);

 

 

SmtpClient mailClient = new SmtpClient("smtp.live.com", 25);

System.Net.

 

NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("myemail@hotmail.com", "mypassword");

mailClient.DeliveryMethod = System.Net.Mail.

 

SmtpDeliveryMethod.Network;

 

mailClient.UseDefaultCredentials =

 

false;

mailClient.EnableSsl =

 

true;

mailClient.Credentials = SMTPUserInfo;

mailClient.Send(message);

message.Dispose();

}

}

}

Link to comment
Share on other sites

The code is sound, and it works on NS you said, I have this strong suspicion that changing:

mailClient.EnableSsl = true;

to:

mailClient.EnableSsl = false;

will be the magic solution.

Link to comment
Share on other sites

I think you should switch the port number to 587, if that doesn't help I'm not really sure what does, that seems to be a common error with no clear-cut solution.

 

In the event it still gives an error, check your MX records and if those are good I'll just try to write up a slightly easier alternative.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...