Create/Send Office Outlook Email

  • Thread starter Thread starter jp2msft
  • Start date Start date
J

jp2msft

I've got some forms that our internal application has generated, and our
departments want the ability to email these reports to others.

Whenever I create HTML pages, I can display them quickly using:
Process.Start("IExplore.exe", m_strPhoneFile); // C#

How would I go about sending an Office Outlook Email?

Can my file still have the HTML extension, or should I rename it to ".EML"
or something?

Where is the executable for Office Outlook stored?
 
For what it is worth:

I do not intend or need to actually send the message. The application I am
building simply needs to be able to create a new Outlook Email message, write
my data to it, then call it using Office Outlook. The individual will select
the people that the message is being sent to, and they will also manually
click the "Send" button.

I've found the "Outlook" COM object that I have referenced in VS2005 Pro,
but I still don't see a way to create a new message.
 
jp2msft said:
I've got some forms that our internal application has generated, and our
departments want the ability to email these reports to others.

Whenever I create HTML pages, I can display them quickly using:
Process.Start("IExplore.exe", m_strPhoneFile); // C#

How would I go about sending an Office Outlook Email?

Process.Start(mailto:[email protected]?subject=test&body=test");

Take subject and body away if you don't need them.

-Teemu
 
The body needs to be a 722 kb HTML document that I created. I'm not sure if
the technique you have listed below will work.

Is there a way to use your technique while specifying a file to use as the
message?
 
jp2msft said:
The body needs to be a 722 kb HTML document that I created. I'm not sure
if
the technique you have listed below will work.

Is there a way to use your technique while specifying a file to use as the
message?

No, it's not possible with this way.

Is it necessary to post the message with Outlook? There is an easy way to
send post with .NET Framework allowing also HTML-messages.

-Teemu
 
Yes. It is necessary. This company supplies employees with Microsoft Outlook,
and this internal, desktop application needs to be able to send reports using
what the company has supplied. From what I have seen, Visual Studio uses POP3
mail protocol, but not everyone here at the company has Internet access.

If the technique you describe below is different from this, please let me
know.
 
I found a really nice way to send emails using Office Outlook:

Code:
// using Outlook = Microsoft.Office.Interop.Outlook;
// string m_strAssignmentFile;
// private string GetAssignments();
public void SendMail() {
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem email = (Outlook.MailItem)
(oApp.CreateItem(Outlook.OlItemType.olMailItem));
Cursor old = Cursor.Current;
Cursor.Current = Cursors.AppStarting;
if ((m_strAssignmentFile == "") || (File.Exists(m_strAssignmentFile) !=
true))
{
m_strAssignmentFile = GetAssignments();
}
email.Subject = "Assignment List";
email.BodyFormat =
Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
if ((strFile != "") && (start == true))
{
StreamReader reader = new StreamReader(m_strAssignmentFile);
try
{
email.HTMLBody = reader.ReadToEnd();
email.Importance = Outlook.OlImportance.olImportanceNormal;
email.Display(true);
}
catch (Exception eDat)
{
string msg = "Error Creating Email:\n" + eDat.Message;
MessageBox.Show(msg);
return;
}
finally
{
reader.Close();
}
}
Cursor.Current = old;
}

I hope someone finds this helpful.
 
Back
Top