Hi,
i would like to send a mail with Outlook.
Here's the source:
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;
using Outlook;
namespace phone_message
{
/// <summary>
/// Summary description for Form1.
/// </summary>
///
public class OutlookMail
{
//private Outlook.Application oApp;
private Outlook.ApplicationClass oApp;
private Outlook._NameSpace oNameSpace;
private Outlook.MAPIFolder oOutboxFolder;
public OutlookMail()
{
oApp = new Outlook.ApplicationClass();
oNameSpace = oApp.GetNamespace("MAPI"
oNameSpace.Logon(null,null,true,true);
//gets defaultfolder for my outlook Outbox
oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
}
}
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button2;
/// <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 );
}
static void Main()
{
Application.Run(new Form1());
}
public void button1_Click(object sender, System.EventArgs e)
{
// create a new MailItem object
Outlook.MailItem oMailItem = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.To = textBox1.Text;
oMailItem.Subject = textBox1.Text;
oMailItem.Body = textBox2.Text;
// save this in your draft
//oMailItem.SaveSentMessageFolder = oOutboxFolder;
//oMailItem.Save();
// add it to the outbox
oMailItem.Send();
mail.From = textBox1.Text;
mail.To = comboBox1.Text;
mail.Subject = "Phone Message from: " + textBox1.Text;
mail.Body = textBox2.Text;
SmtpMail.Send(mail);
MessageBox.Show("Message sent to " + comboBox1.Text);*/
}
private void button2_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}
I work with Outlook 2000.
The error is here:
// create a new MailItem object
Outlook.MailItem oMailItem = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
----
Message:
The type or namespace name 'oApp' could not be found (are you missing a using directive or an assembly reference?)
Can someone help me?
Thanks,
Stephanie
i would like to send a mail with Outlook.
Here's the source:
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;
using Outlook;
namespace phone_message
{
/// <summary>
/// Summary description for Form1.
/// </summary>
///
public class OutlookMail
{
//private Outlook.Application oApp;
private Outlook.ApplicationClass oApp;
private Outlook._NameSpace oNameSpace;
private Outlook.MAPIFolder oOutboxFolder;
public OutlookMail()
{
oApp = new Outlook.ApplicationClass();
oNameSpace = oApp.GetNamespace("MAPI"
oNameSpace.Logon(null,null,true,true);
//gets defaultfolder for my outlook Outbox
oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
}
}
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button2;
/// <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 );
}
static void Main()
{
Application.Run(new Form1());
}
public void button1_Click(object sender, System.EventArgs e)
{
// create a new MailItem object
Outlook.MailItem oMailItem = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.To = textBox1.Text;
oMailItem.Subject = textBox1.Text;
oMailItem.Body = textBox2.Text;
// save this in your draft
//oMailItem.SaveSentMessageFolder = oOutboxFolder;
//oMailItem.Save();
// add it to the outbox
oMailItem.Send();
mail.From = textBox1.Text;
mail.To = comboBox1.Text;
mail.Subject = "Phone Message from: " + textBox1.Text;
mail.Body = textBox2.Text;
SmtpMail.Send(mail);
MessageBox.Show("Message sent to " + comboBox1.Text);*/
}
private void button2_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}
I work with Outlook 2000.
The error is here:
// create a new MailItem object
Outlook.MailItem oMailItem = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
----
Message:
The type or namespace name 'oApp' could not be found (are you missing a using directive or an assembly reference?)
Can someone help me?
Thanks,
Stephanie