Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send eMail with Outlook

Status
Not open for further replies.

lutzs

Programmer
Oct 8, 2002
75
LU
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(&quot;MAPI&quot;);
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 = &quot;Phone Message from: &quot; + textBox1.Text;
mail.Body = textBox2.Text;
SmtpMail.Send(mail);

MessageBox.Show(&quot;Message sent to &quot; + 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
 
Don't.....

You;re using a COM interface when there is a .NET class to do this....

Look up System.Web.Mail.SmtpMail in help.....it will do all you want without reliance on a particular client....

Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top