hey i am trying to create an email application but when i run it i
get the error -- could not access 'CDO.Message'object --
The code that i am using is shown below ==
*****************************************************************
*****************************************************************
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Web;
using System.Web.Mail;
namespace WindowsApplication7
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Button SendButton;
private System.Windows.Forms.Button BrowseButton;
private System.Windows.Forms.OpenFileDialog
openFileDialog1;
private System.Windows.Forms.TextBox FromTextBox;
private System.Windows.Forms.TextBox ToTextBox;
private System.Windows.Forms.TextBox CCTextBox;
private System.Windows.Forms.TextBox BCCTextBox;
private System.Windows.Forms.TextBox SubjectTextBox;
private System.Windows.Forms.TextBox
AttachmentTextBox;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox MessageTextBox;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components =
null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after
InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.FromTextBox = new
System.Windows.Forms.TextBox();
this.ToTextBox = new
System.Windows.Forms.TextBox();
this.CCTextBox = new
System.Windows.Forms.TextBox();
this.BCCTextBox = new
System.Windows.Forms.TextBox();
this.SubjectTextBox = new
System.Windows.Forms.TextBox();
this.AttachmentTextBox = new
System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label
();
this.label2 = new System.Windows.Forms.Label
();
this.label3 = new System.Windows.Forms.Label
();
this.label4 = new System.Windows.Forms.Label
();
this.label5 = new System.Windows.Forms.Label
();
this.label6 = new System.Windows.Forms.Label
();
this.BrowseButton = new
System.Windows.Forms.Button();
this.SendButton = new
System.Windows.Forms.Button();
this.openFileDialog1 = new
System.Windows.Forms.OpenFileDialog();
this.MessageTextBox = new
System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button
();
this.SuspendLayout();
//
// FromTextBox
//
this.FromTextBox.Location = new
System.Drawing.Point(88, 16);
this.FromTextBox.Name = "FromTextBox";
this.FromTextBox.Size = new
System.Drawing.Size(320, 20);
this.FromTextBox.TabIndex = 0;
this.FromTextBox.Text = "";
//
// ToTextBox
//
this.ToTextBox.Location = new
System.Drawing.Point(88, 48);
this.ToTextBox.Name = "ToTextBox";
this.ToTextBox.Size = new System.Drawing.Size
(320, 20);
this.ToTextBox.TabIndex = 1;
this.ToTextBox.Text = "";
//
// CCTextBox
//
this.CCTextBox.Location = new
System.Drawing.Point(88, 80);
this.CCTextBox.Name = "CCTextBox";
this.CCTextBox.Size = new System.Drawing.Size
(320, 20);
this.CCTextBox.TabIndex = 2;
this.CCTextBox.Text = "";
//
// BCCTextBox
//
this.BCCTextBox.Location = new
System.Drawing.Point(88, 112);
this.BCCTextBox.Name = "BCCTextBox";
this.BCCTextBox.Size = new System.Drawing.Size
(320, 20);
this.BCCTextBox.TabIndex = 3;
this.BCCTextBox.Text = "";
//
// SubjectTextBox
//
this.SubjectTextBox.Location = new
System.Drawing.Point(88, 144);
this.SubjectTextBox.Name = "SubjectTextBox";
this.SubjectTextBox.Size = new
System.Drawing.Size(320, 20);
this.SubjectTextBox.TabIndex = 4;
this.SubjectTextBox.Text = "";
//
// AttachmentTextBox
//
this.AttachmentTextBox.Location = new
System.Drawing.Point(88, 176);
this.AttachmentTextBox.Name
= "AttachmentTextBox";
this.AttachmentTextBox.Size = new
System.Drawing.Size(240, 20);
this.AttachmentTextBox.TabIndex = 5;
this.AttachmentTextBox.Text = "";
//
// label1
//
this.label1.Location = new
System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size
(48, 23);
this.label1.TabIndex = 6;
this.label1.Text = "From";
//
// label2
//
this.label2.Location = new
System.Drawing.Point(8, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size
(40, 23);
this.label2.TabIndex = 7;
this.label2.Text = "To";
//
// label3
//
this.label3.Location = new
System.Drawing.Point(8, 176);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size
(64, 16);
this.label3.TabIndex = 8;
this.label3.Text = "Atachments";
//
// label4
//
this.label4.Location = new
System.Drawing.Point(8, 80);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size
(40, 23);
this.label4.TabIndex = 9;
this.label4.Text = "Cc";
//
// label5
//
this.label5.Location = new
System.Drawing.Point(8, 112);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size
(40, 23);
this.label5.TabIndex = 10;
this.label5.Text = "Bcc";
//
// label6
//
this.label6.Location = new
System.Drawing.Point(8, 144);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size
(48, 23);
this.label6.TabIndex = 11;
this.label6.Text = "Subject";
//
// BrowseButton
//
this.BrowseButton.Location = new
System.Drawing.Point(336, 176);
this.BrowseButton.Name = "BrowseButton";
this.BrowseButton.Size = new
System.Drawing.Size(72, 24);
this.BrowseButton.TabIndex = 12;
this.BrowseButton.Text = "Browse";
this.BrowseButton.Click += new
System.EventHandler(this.BrowseButton_Click);
//
// SendButton
//
this.SendButton.Location = new
System.Drawing.Point(120, 440);
this.SendButton.Name = "SendButton";
this.SendButton.TabIndex = 13;
this.SendButton.Text = "Send";
this.SendButton.Click += new
System.EventHandler(this.SendButton_Click);
//
// MessageTextBox
//
this.MessageTextBox.Location = new
System.Drawing.Point(8, 216);
this.MessageTextBox.Multiline = true;
this.MessageTextBox.Name = "MessageTextBox";
this.MessageTextBox.ScrollBars =
System.Windows.Forms.ScrollBars.Both;
this.MessageTextBox.Size = new
System.Drawing.Size(408, 200);
this.MessageTextBox.TabIndex = 14;
this.MessageTextBox.Text = "";
//
// button1
//
this.button1.Location = new
System.Drawing.Point(232, 440);
this.button1.Name = "button1";
this.button1.TabIndex = 15;
this.button1.Text = "Exit";
//
// Form1
//
this.AutoScaleBaseSize = new
System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size
(424, 485);
this.Controls.Add(this.button1);
this.Controls.Add(this.MessageTextBox);
this.Controls.Add(this.SendButton);
this.Controls.Add(this.BrowseButton);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.AttachmentTextBox);
this.Controls.Add(this.SubjectTextBox);
this.Controls.Add(this.BCCTextBox);
this.Controls.Add(this.CCTextBox);
this.Controls.Add(this.ToTextBox);
this.Controls.Add(this.FromTextBox);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler
(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void SendButton_Click(object sender,
System.EventArgs e)
{
try
{
// Construct a new mail message and
fill it with information from the form
MailMessage aMessage = new MailMessage
();
aMessage.From = FromTextBox.Text;
aMessage.To = ToTextBox.Text;
aMessage.Cc = CCTextBox.Text;
aMessage.Bcc = BCCTextBox.Text;
aMessage.Subject =
SubjectTextBox.Text;
aMessage.Body = MessageTextBox.Text;
// if an attachment file is
indicated, create it and add it to the message
if (AttachmentTextBox.Text.Length > 0)
aMessage.Attachments.Add(new
MailAttachment(AttachmentTextBox.Text, MailEncoding.Base64));
// Now send the message
SmtpMail.Send(aMessage);
// Indicate that the message has been
sent
MessageBox.Show("Message Sent to " +
ToTextBox.Text);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString
());
}
}
private void BrowseButton_Click(object sender,
System.EventArgs e)
{
if (this.openFileDialog1.ShowDialog() ==
DialogResult.OK)
{
AttachmentTextBox.Text =
this.openFileDialog1.FileName;
}
}
private void Form1_Load(object sender,
System.EventArgs e)
{
}
}
}
********************************************************************
********************************************************************
Any ideas welcome
thanks
Dave
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspClassicAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/