Hello,
I'm implementing a console aplication in C#, wich send e-mails using Outlook 2003. It work fine but, before the message is sending, a small box is appearing on the desktop( Object model security). It seems to happen because my code is unsafed. How can I write the following code in trusted mode?
namespace SendHTMLMail
{
public class Class1
{
public static int Main(string[] args)
{
try
{
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Get the NameSpace and Logon information.
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Log on by using a dialog box to choose the profile.
oNS.Logon(Missing.Value, Missing.Value, true, true);
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set the subject.
oMsg.Subject = "Send Using OOM in C#";
// Set HTMLBody.
String body = "Hello WOrld!";
oMsg.HTMLBody = sHtml;
// Add a recipient.
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("email address");
oRecip.Resolve();
// Send.
oMsg.Send();
// Log off.
oNS.Logoff();
// Clean up.
oRecip = null;
oRecips = null;
oMsg = null;
oNS = null;
oApp = null;
}
// Simple error handling.
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
// Default return value.
return 0;
}
}
}
If some one of you know to do it by Visual Basic is well too.
Thank you!
I'm implementing a console aplication in C#, wich send e-mails using Outlook 2003. It work fine but, before the message is sending, a small box is appearing on the desktop( Object model security). It seems to happen because my code is unsafed. How can I write the following code in trusted mode?
namespace SendHTMLMail
{
public class Class1
{
public static int Main(string[] args)
{
try
{
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Get the NameSpace and Logon information.
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Log on by using a dialog box to choose the profile.
oNS.Logon(Missing.Value, Missing.Value, true, true);
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set the subject.
oMsg.Subject = "Send Using OOM in C#";
// Set HTMLBody.
String body = "Hello WOrld!";
oMsg.HTMLBody = sHtml;
// Add a recipient.
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("email address");
oRecip.Resolve();
// Send.
oMsg.Send();
// Log off.
oNS.Logoff();
// Clean up.
oRecip = null;
oRecips = null;
oMsg = null;
oNS = null;
oApp = null;
}
// Simple error handling.
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
// Default return value.
return 0;
}
}
}
If some one of you know to do it by Visual Basic is well too.
Thank you!