Security/Permission with sending e-mails

J

Jax

Behold the code that doesnt work

using System
using Outlook

namespace EmailAp

/// <summary
/// Summary description for SendingEmail
/// </summary
public class SendingEmai

public SendingEmail(

/
// TODO: Add constructor logic her
/

[STAThread
static void Main(string[] args

Console.WriteLine("Sending e-mail")
string s = SendingEmail.SendEmail("(e-mail address removed)", "someSubject", "Blah blah")
Console.WriteLine("Return message is: " + s)
Console.ReadLine()

public static string SendEmail(string to, string subject, string text

Outlook.Application ol
Outlook.NameSpace ns
Outlook.MailItem objmail
tr

//Open Namespac
ol = new Outlook.Application()

ns = ol.GetNamespace("MAPI")

ns.Logon("", "", false, true)

objmail = (Outlook.MailItem) ol.CreateItem(Outlook.OlItemType.olMailItem)
objmail.To = to
objmail.Body = text
objmail.Subject = subject

objmail.Send()
}
catch(System.Exception e

return e.ToString()

return "Success"




Dont get me wrong, this does work, but only on my p.c. I copy it across to a work colleage and it doesn't work at all
What permissions doe I need to observe? Is it something I have to set up in windows? Or can I fix thisfrom code by using a different constructor or something
I want to use this code to send me eMails whenever an exception occurs in my program so I can assess performance when others are using it, is there a better method than this
Many thanks for any assistanc

jax
 
S

Sue Mosher [MVP-Outlook]

What in particular doesn't work? Is the message not created? Not sent? Does
the other person have Outlook installed? Is Outlook already running at the
time your code runs?
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Jax said:
Behold the code that doesnt work,

using System;
using Outlook;

namespace EmailApp
{
/// <summary>
/// Summary description for SendingEmail.
/// </summary>
public class SendingEmail
{
public SendingEmail()
{
//
// TODO: Add constructor logic here
//
}
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Sending e-mail");
string s = SendingEmail.SendEmail("(e-mail address removed)", "someSubject", "Blah blah");
Console.WriteLine("Return message is: " + s);
Console.ReadLine();
}
public static string SendEmail(string to, string subject, string text)
{
Outlook.Application ol;
Outlook.NameSpace ns;
Outlook.MailItem objmail;
try
{
//Open Namespace
ol = new Outlook.Application();

ns = ol.GetNamespace("MAPI");

ns.Logon("", "", false, true);

objmail = (Outlook.MailItem) ol.CreateItem(Outlook.OlItemType.olMailItem);
objmail.To = to;
objmail.Body = text;
objmail.Subject = subject;

objmail.Send();
} }
catch(System.Exception e)
{
return e.ToString();
}
return "Success";
}
}
}

Dont get me wrong, this does work, but only on my p.c. I copy it across to
a work colleage and it doesn't work at all.
What permissions doe I need to observe? Is it something I have to set up
in windows? Or can I fix thisfrom code by using a different constructor or
something?
I want to use this code to send me eMails whenever an exception occurs in
my program so I can assess performance when others are using it, is there a
better method than this?
 
J

Jax

Thanks for replying sue

I did actually sort it out, it's because we were testing it on another p.c, but that p.c was running the .exe over the network rather then copying the .exe to their HD and running it. Which is how it will be deployed anyway
Hooray all sorted

jax
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top