0

In my application, I need to send emails. I can' t use smtp and there is no option installing MS Outlook in normal ways. I tried;

private Microsoft.Office.Interop.Outlook.Application oApp;
private Microsoft.Office.Interop.Outlook._NameSpace oNameSpace;
private Microsoft.Office.Interop.Outlook.MAPIFolder oOutboxFolder;

oApp = new Outlook.Application();
oNameSpace = oApp.GetNamespace("MAPI");
oNameSpace.Logon(null, null, true, true);

Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.
    CreateItem(Outlook.OlItemType.olMailItem);

    oMailItem.To = toValue;
    oMailItem.Subject = subjectValue;
    oMailItem.Body = bodyValue;
    oMailItem.Send();

This code works well if Office 2010 is installed and running on machine. But I need to find out what dlls are being referenced. Is it possible to get only required dlls from Outlook and send email using them?

Thanks in advance

Alpay
  • 1,350
  • 2
  • 24
  • 56
  • As an aside, this is why Hungarian Notation fell out of popularity; since everything is an object, all variables end up being prefixed with an *o*. – Yuck Apr 03 '13 at 11:00
  • These `o`s were ment to be Outlook' s `O`s :) – Alpay Apr 03 '13 at 11:02
  • 1
    If you are attempting to send emails using the outlook DLLs i'm assuming there is an Exchange server in the mix somewhere, can you not use the Exchange Web Services to perform the task? – Chris Apr 03 '13 at 11:02
  • This might also be an option, but I couldn' t find any example or something that shows how to use it that way. Can you provide any examples? – Alpay Apr 03 '13 at 11:04
  • @Alpay see answer below, put in some examples and links to where i originally got my information from. – Chris Apr 03 '13 at 11:14

1 Answers1

1

As per comment, examples of how to use the Exchange Web Services to send emails through an exchange server. Most of the information is available from the following link copied into the answer for preservation.

Example of creating an email message and sending it ( with a copy in the sent items folder of the user )

// Create an email message and identify the Exchange service.
EmailMessage message = new EmailMessage(service);

// Add properties to the email message.
message.Subject = "Interesting";
message.Body = "The merger is finalized.";
message.ToRecipients.Add("user1@contoso.com");

// Send the email message and save a copy.
message.SendAndSaveCopy();

More code on the creation here

Slightly more complicated is the instantiation of the service variable used in the above code. Which is available here

ExchangeService service = new ExchangeService();
service.Credentials = new WebCredentials("user1@contoso.com", "password");
service.AutodiscoverUrl("user1@contoso.com");

Which will attempt to autodiscover the url of the exchange services from the email address. It is worth noting however that calls to the service will fail unless you attach a callback method to validate a self signed certificate which is used by default by Exchange. More info here

There is a wealth of information on how to connect to exchange services, send emails, create meetings, and calender requests. I have yet to personally test all of the above but probably gives you a decent start.

Chris
  • 3,114
  • 1
  • 18
  • 27