here açıklandığı gibi Outlook aracılığıyla e-posta göndermek istiyorum. Outlook'u zaten açtığım sürece iyi çalışıyor. Örneğin, örneğin Outlook küçültülmüş ve kodumu çalıştırırsam, bir e-posta gönderebilirim. Outlook kapalı Ama eğer bir istisna olsun: KodOutlook açıldığında Outlook'u yalnızca e-posta gönderebilir
İşte{System.Runtime.InteropServices.COMException (0x80004004): Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))
at Microsoft.Office.Interop.Outlook._MailItem.get_Recipients()
at OutlookExample.Form1.btnSendEmail_Click(Object sender, EventArgs e) in C:\Users\abc\Documents\Visual Studio 2008\Projects\OutlookExample\OutlookExample\Form1.cs:line 28}
geçerli:
using Outlook = Microsoft.Office.Interop.Outlook;
...
private void btnSendEmail_Click(object sender, EventArgs e)
{
try
{
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMsg.HTMLBody = "Hello, here is your message!";
oMsg.Subject = "This is a test message";
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("[email protected]");
oRecip.Resolve();
oMsg.Send();
oRecip = null;
oRecips = null;
oMsg = null;
oApp = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
neden değil bu iş?
Düzenleme: outlook açık olsaydı onun açtı değilse
app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace ns = app.GetNamespace("MAPI");
f = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
Thread.Sleep(5000); // a bit of startup grace time.
zahmete kullanır: Burada
using Outlook = Microsoft.Office.Interop.Outlook;
...
private void btnSendEmail_Click(object sender, EventArgs e)
{
try
{
Outlook.Application oApp = new Outlook.Application();
// These 3 lines solved the problem
Outlook.NameSpace ns = oApp.GetNamespace("MAPI");
Outlook.MAPIFolder f = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
System.Threading.Thread.Sleep(5000); // test
Outlook.MailItem oMsg = Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMsg.HTMLBody = "Hello, here is your message!";
oMsg.Subject = "This is a test message";
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("[email protected]");
oRecip.Resolve();
oMsg.Send();
oRecip = null;
oRecips = null;
oMsg = null;
oApp = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Outlook kullanmayın edildi. Bunun yerine, System.Net.Mail'i kullanın. – SLaks
İyi soru. Henüz giriş yapmadığından emin misin? – BugFinder
SLaks, Keşke. Ne yazık ki ben VB6 kodu koruyorum ve sadece C# içinde sorunu çoğaltılır. –