- 我在這裏所做的是與復發發送電子郵件和 這已被自動添加到接收器的Outlook日曆 這相當奏效。
- 另一方面,我的服務器沒有Outlook所以我想 做沒有使用Outlook發送預約重複。
<asp:Label ID="lbError" runat="server"></asp:Label>
<br />
<asp:Button ID="btSent" runat="server" OnClick="btSent_Click" Text="Sent" />
<br />
<br />
<asp:Label ID="lbRecur" runat="server"></asp:Label>
C#:
protected void btSent_Click(object sender, EventArgs e)
{
SendMail("[email protected]", "ITD");
}
public void SendMail(string targetMail, string shownTargetName)
{
MailAddress fromAddress = new MailAddress("[email protected]", "MailSendingProgram");
MailAddress toAddress = new MailAddress(targetMail, shownTargetName);
String fromPassword = "mypassword";
String subject = "Test Recurrence";
String body =
@"
Here you can put in any text that will appear in the body
multilined and even in <html>
";
SmtpClient smtp = new SmtpClient
{
Host = "RSC-MAIL2K7.abc.com",
Port = 25,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (MailMessage message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
}
)
{
try
{
smtp.Send(message);
lbError.Text = "E-Mail sent!";
Outlook.Application olApp = new Outlook.Application();
CreateNewRecurringAppointment(olApp);
Marshal.ReleaseComObject(olApp);
}
catch
{
lbError.Text = "Sending failed, check your internet connection!";
}
}
}
public void CreateNewRecurringAppointment(Outlook._Application OutlookApp)
{
Outlook.AppointmentItem appItem = null;
Outlook.RecurrencePattern pattern = null;
try
{
appItem = OutlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem)
as Outlook.AppointmentItem;
// create a recurrence
pattern = appItem.GetRecurrencePattern();
pattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursWeekly;
pattern.StartTime = DateTime.Parse("8:35:00 AM");
pattern.EndTime = DateTime.Parse("9:35:00 PM");
// we can specify the duration instead of using the EndTime property
pattern.Duration = 60;
pattern.PatternStartDate = DateTime.Parse("07/23/2014");
pattern.PatternEndDate = DateTime.Parse("07/31/2014");
appItem.Subject = "Meeting with the Boss";
appItem.Body = "Test Appointment body";
appItem.Location = "P1";
appItem.ReminderSet = true;
appItem.ReminderMinutesBeforeStart = 15;
appItem.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh;
appItem.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy;
appItem.Save();
appItem.Send();
//appItem.Display(true);
}
catch (Exception ex)
{
lbRecur.Text = ex.Message;
}
finally
{
if (pattern != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(pattern);
}
if (appItem != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(appItem);
}
}
}
,什麼是這裏的問題? –
你可以手動創建一個[ICalendar](http://en.wikipedia.org/wiki/ICalendar)文件,並通過電子郵件發送名爲invite.ics的附件,該文件應該可以做到這一點 – pushpraj
@ LasseV.Karlsen:My問題是「我希望在不使用Outlook的情況下發送預約重複」。 –