Abacus IT
asked on
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.O utlook, 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.
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();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER