Solved

Emailing through Outlook 2007 from VS2008 C# project.

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Resolve DNS query failed errors for Exchange
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

863 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

25 Experts available now in Live!

Get 1:1 Help Now