Solved

Emailing through Outlook 2007 from VS2008 C# project.

Posted on 2010-08-17
3
396 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 69

Accepted Solution

by:
Éric Moreau earned 500 total points
Comment Utility
0
 
LVL 1

Author Comment

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

Expert Comment

by:Comtek
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Email signatures have numerous marketing benefits. Here are 8 top reasons to turn your email signature into a marketing channel.
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…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
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: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now