Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

Emailing through Outlook 2007 from VS2008 C# project.

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
Abacus IT
Asked:
Abacus IT
1 Solution
 
Abacus ITAuthor Commented:
I like that solution much better than the route I was taking. Thank you.
0
 
ComtekCommented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now