MailMessage msg = new MailMessage("Account@gmail.com", "Account6@gmail.com", "test", "test");

 

msg = GetCalanderInviteMsg3(msg);

 

SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);

 

smtp.Credentials = new NetworkCredential("Account", "password");

 

smtp.EnableSsl = true;

 

smtp.Send(msg);



public static MailMessage GetCalanderInviteMsg3(MailMessage msg){

 

StringBuilder sb = new StringBuilder();

 

sb.AppendLine("BEGIN:VCALENDAR");

 

sb.AppendLine("PRODID:-//Google Inc//Google Calendar 70.9054//EN");

 

sb.AppendLine("VERSION:2.0");

 

sb.AppendLine("METHOD:REQUEST");

 

sb.AppendLine("BEGIN:VEVENT");

 

sb.AppendLine("DTSTART:20130227T040705Z");

 

sb.AppendLine("DTEND:20130227T040705Z");

 

sb.AppendLine("DTSTAMP:20130127T040705Z");

 

sb.AppendLine("UID:" + Guid.NewGuid());

 

sb.AppendLine("CREATED:20130624T082605Z");

 

sb.AppendLine("DESCRIPTION:");

 

sb.AppendLine("LOCATION:");

 

sb.AppendLine("END:VEVENT");

 

sb.AppendLine("END:VCALENDAR");

 

//content type 必須設定成 text/calendar
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");

 

ct.Parameters.Add("method", "REQUEST");

 

AlternateView avCal = AlternateView.CreateAlternateViewFromString(sb.ToString(), ct);

 

msg.AlternateViews.Add(avCal);

 

return msg;

 

}
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()