faramarz_s
شنبه 19 مهر 1382, 06:34 صبح
اصل برنامه ساده و کاملا مشخص است:::ارسال نامه به فردی از طریق وبفرمها
using System;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.Mail;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace sendMail
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Label lblResult;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.RegularExpressionValidat or RegularExpressionValidator1;
protected System.Web.UI.WebControls.TextBox TextBox2;
public string getConnectionStrFromWebConfig(string webConfigKey_ConnectionStr)
{
// the best way for getting state from web.config
return System.Configuration.ConfigurationSettings.AppSett ings[webConfigKey_ConnectionStr];
}
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
MailMessage Mailer = new MailMessage();
Mailer.From = TextBox1.Text;
Mailer.To = "faramarz_s@hotmail.com";
Mailer.Subject = TextBox2.Text;
Mailer.Body = TextBox3.Text;
Mailer.BodyFormat = System.Web.Mail.MailFormat.Html;
SmtpMail.Send(Mailer);
lblResult.Visible=true;
lblResult.Text="نامه شما با موفقیت ارسال گردید";
}
catch(Exception ex)
{
lblResult.Visible=true;
lblResult.Text = "خطا در ارسال نامه! " + ex.ToString();
}
}
}
}
نتیجه امتحان برنامه بر روی هاست:
خطا در ارسال نامه! System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80040220): The "SendUsing" configuration value is invalid. --- End of inner exception stack trace --- at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject obj, String methodName, Object[] args) --- End of inner exception stack trace --- at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject obj, String methodName, Object[] args) at System.Web.Mail.CdoSysHelper.Send(MailMessage message) at System.Web.Mail.SmtpMail.Send(MailMessage message) at sendMail.WebForm1.Button1_Click(Object sender, EventArgs e) in d:\inetpub\wwwroot\projects\sendmail\default.aspx. cs:line 80
using System;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.Mail;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace sendMail
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Label lblResult;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.RegularExpressionValidat or RegularExpressionValidator1;
protected System.Web.UI.WebControls.TextBox TextBox2;
public string getConnectionStrFromWebConfig(string webConfigKey_ConnectionStr)
{
// the best way for getting state from web.config
return System.Configuration.ConfigurationSettings.AppSett ings[webConfigKey_ConnectionStr];
}
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
MailMessage Mailer = new MailMessage();
Mailer.From = TextBox1.Text;
Mailer.To = "faramarz_s@hotmail.com";
Mailer.Subject = TextBox2.Text;
Mailer.Body = TextBox3.Text;
Mailer.BodyFormat = System.Web.Mail.MailFormat.Html;
SmtpMail.Send(Mailer);
lblResult.Visible=true;
lblResult.Text="نامه شما با موفقیت ارسال گردید";
}
catch(Exception ex)
{
lblResult.Visible=true;
lblResult.Text = "خطا در ارسال نامه! " + ex.ToString();
}
}
}
}
نتیجه امتحان برنامه بر روی هاست:
خطا در ارسال نامه! System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80040220): The "SendUsing" configuration value is invalid. --- End of inner exception stack trace --- at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject obj, String methodName, Object[] args) --- End of inner exception stack trace --- at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject obj, String methodName, Object[] args) at System.Web.Mail.CdoSysHelper.Send(MailMessage message) at System.Web.Mail.SmtpMail.Send(MailMessage message) at sendMail.WebForm1.Button1_Click(Object sender, EventArgs e) in d:\inetpub\wwwroot\projects\sendmail\default.aspx. cs:line 80