Solved

Emailing through Outlook 2007 from VS2008 C# project.

Posted on 2010-08-17
3
404 Views
Last Modified: 2012-05-10
I am trying to email out from my C# project an email to specific users that are stored in a table in a local SQL server table. I have added in the Microsoft.Office.Core, Microsoft.Office.Interop.Outlook, and Microsoft Office 12.0 Outlook references. I also added the using statements for the first 2 to my project code page, but when I attempt to build, I get an error statement saying:

Error      1      The type or namespace name 'Outlook' could not be found (are you missing a using directive or an assembly reference?)

I'm not sure what statement I am missing or reference I'm missing, but if I could get some assistance with this it would be much appreciated. I will attach the code I have so far for the emailing process. I have also tested the email using SMTP, which works fine, but the deployed project will not be able to use SMTP.

public void MainStart()
{
         string emailAddress = GetSystemSettings("emailAddress1");
         string emailSubject = GetSystemSettings("emailSubject");
         string emailMessage = GetSystemSettings("emailMessage");

         addToInBox(emailAddress, emailSubject, emailMessage);
}
public void AddToOutbox(string toValue, string subjectValue, string bodyValue)
{
       Outlook.Application oApp = null;
       Outlook.MailItem oMsg = null;
       Outlook.Inspector oAddSig = null;

       oApp = new Outlook.Application();
       oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
       oAddSig = oMsg.GetInspector;
       Outlook.MAPIFolder oOutboxFolder =       NameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
       oNameSpace.Logon(null, null, false, false);

       Outlook._MailItem oMailItem =  (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
       oMailItem.To = emailAddress;
       oMailItem.Subject = emailSubject;
       oMailItem.Body = emailMessage;
       oMailItem.SaveSentMessageFolder = oOutboxFolder;
           
       //adds it to the outbox
       oMailItem.Send();
}

Open in new window

0
Comment
Question by:Abacus IT
3 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 33454073
0
 
LVL 1

Author Comment

by:Abacus IT
ID: 33454130
I like that solution much better than the route I was taking. Thank you.
0
 
LVL 2

Expert Comment

by:Comtek
ID: 33454345
Can't you just send the email directly to your email server rather than using the client's Outlook? That would be a much cleaner setup.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Read this checklist to learn more about the 15 things you should never include in an email signature.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question