I've been playing with your code this evening, but could not really get it to work correctly.
I think I understand the code, but am not quite sure as there are many things I have not learned yet. But you have a CS file is called clsMail.cs, which is to control what happens when sending an email.
And in your SQL string you take your info as the user types in the comment box and paste in the database and send an email.
But I do not know if I'm doing it right to add it to my code.
But here's my codebehind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.IO;
public partial class VisBlognyhed : System.Web.UI.Page
{
private int kommentar_ID = 1;
private int indlaeg_ID = 1;
private int myindent = 0;
protected void Page_Load(object sender, EventArgs e)
{
recaptcha.Validate();
if (Request.QueryString["indlaeg_ID"] != null)
{
int q = Convert.ToInt32(Request.QueryString["indlaeg_ID"]);
}
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
Image img = e.Item.FindControl("imgBlog") as Image;
if (img is Image)
{
img.Visible = (img.ImageUrl != "");
}
}
protected void Button_kommentar_Click(object sender, EventArgs e)
{
int mParentId = kommentar_ID;
int mArticleId = indlaeg_ID;
string mUserName = "quartz";
string mUserDato = "quartz@msn.com";
string mDescription = "Test Description";
int mIndent = myindent;
if (Page.IsValid)
{
mUserName = TextBox_navn.Text;
mUserDato = TextBox_dato.Text;
mDescription = TextBox_kommentar.Text;
Label_kommentar.Text = "Korrekt";
Label_kommentar.ForeColor = System.Drawing.Color.Green;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO kommentar (dato, navn, kommentar, fk_indlaeg_ID) VALUES(@dato, @navn, @kommentar, @indlaeg)";
cmd.Parameters.Add("@dato", SqlDbType.DateTime).Value = TextBox_dato.Text;
cmd.Parameters.Add("@navn", SqlDbType.VarChar).Value = TextBox_navn.Text;
cmd.Parameters.Add("@kommentar", SqlDbType.Text).Value = TextBox_kommentar.Text;
cmd.Parameters.Add("@indlaeg", SqlDbType.Int).Value = Request.QueryString["indlaeg_ID"];
cmd.CommandText = "INSERT INTO kommentar (dato, navn, kommentar, fk_indlaeg_ID) VALUES('" +mParentId + "','" + mArticleId + "','" + mUserName + "','" + mUserDato + "','" + mDescription + "','" + "')";
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
TextBox_dato.Text = "";
TextBox_navn.Text = "";
TextBox_kommentar.Text = "";
Label_kommentar.Text = "Din kommentar er modtaget.";
}
else
{
Label_kommentar.Text = "Du skal indtaste Captcha eller du har indtastet forkert";
Label_kommentar.ForeColor = System.Drawing.Color.Red;
}
}
}
And the code for the Class:
using System;
using System.Web.Mail;
namespace JumpyForum
{
public class clsMail
{
public bool SendMail(string ToM, string FromM, string CcM, string MSubject, string MBody )
{
try
{
MailMessage objMM = new MailMessage();
objMM.To = ToM;
objMM.From = FromM;
objMM.Cc = CcM;
objMM.BodyFormat = MailFormat.Html ;
objMM.Priority = MailPriority.Normal;
objMM.Subject = MSubject;
objMM.Body = MBody;
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(objMM);
return true;
}
catch
{
return false;
}
finally
{
}
}
}
}
And in this one MailPriority there is a failed on
Hope you can guide me some more