2017-10-19 103 views
-1

我需要發送與用戶默認電子郵件客戶端的預約(在這種情況下僅用於Outlook),用戶必須打開您的Outlook,我可以從本地程序發送它,但是當它服務器端,我有錯誤,因爲代碼是沒有要(因爲是用戶默認郵件客戶端)只能從用C#發送outlook預約

public void aAppointment(string subject, string body, string date, string start, string end, string location, string attend) 
{ 
    Outlook._NameSpace ns = null;  
    Outlook.Application apptApp = new Outlook.Application(); 
    Outlook.AppointmentItem appt = 
    apptApp.CreateItem(Outlook.OlItemType.olAppointmentItem) as Outlook.AppointmentItem; 
    ns = apptApp.GetNamespace("MAPI"); 
    ns.Logon(null, null, false, false); 
    apptApp.ActiveWindow(); 
    appt.MeetingStatus = Outlook.OlMeetingStatus.olMeeting; 
    appt.Subject = subject; 
    appt.Body = body; 
    appt.AllDayEvent = false; 
    appt.Start = DateTime.Parse(date + " " + start); 
    appt.Location = location; 
    appt.End = DateTime.Parse(date + " " + end);  
    appt.RequiredAttendees = attend; 
    appt.Display(false); 
} 

嘗試在本地環境的它的確定,打開新的Outlook約會,但在服務器環境有認證錯誤,服務器有前景,但我認爲,錯誤是因爲沒有最終用戶機器的憑據

Thx for your answers

+1

在服務器環境中使用Office Interop是一個糟糕的主意,難怪你頭疼。 – Equalsk

+0

Jeje它的真實,什麼是一個好方法? –

回答

0

與任何Office應用程序一樣,Outlook不能用於服務(如IIS)。創建一個內容類型爲「text/calendar」的MIME消息,並使用直接SMTP發送iCal數據。