Public Sub Sendmail_With_IcsAttachment()
Try
Dim msg As New MailMessage()
Dim str As New StringBuilder()
msg.From = New MailAddress("[email protected]", "ABC")
msg.[To].Add(New MailAddress("[email protected]", "BCD"))
msg.Subject = TextBox1.Text
msg.Body = "Please Attend the meeting with this schedule"
str.AppendLine("BEGIN:VCALENDAR")
str.AppendLine("PRODID:-//Schedule a Meeting")
str.AppendLine("VERSION:2.0")
str.AppendLine("METHOD:REQUEST")
str.AppendLine("BEGIN:VEVENT")
str.AppendLine(String.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", DateTime.Now.ToUniversalTime))
str.AppendLine(String.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.Now.ToUniversalTime))
str.AppendLine(String.Format("DTEND:{0:yyyyMMddTHHmmssZ}", DateTime.Now.AddMinutes(+20).ToUniversalTime))
str.AppendLine(String.Format("UID:{0}", Guid.NewGuid()))
str.AppendLine(String.Format("DESCRIPTION:{0}", msg.Body))
str.AppendLine(String.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", msg.Body))
str.AppendLine(String.Format("SUMMARY:{0}", msg.Subject))
str.AppendLine(String.Format("ORGANIZER:MAILTO:{0}", msg.From.Address))
str.AppendLine(String.Format("ATTENDEE;CN=""{0}"";RSVP=TRUE:mailto:{1}", msg.[To](0).DisplayName, msg.[To](0).Address))
str.AppendLine("BEGIN:VALARM")
str.AppendLine("TRIGGER:-PT15M")
str.AppendLine("ACTION:DISPLAY")
str.AppendLine("DESCRIPTION:Reminder")
str.AppendLine("END:VALARM")
str.AppendLine("END:VEVENT")
str.AppendLine("END:VCALENDAR")
Dim smtpclient As New System.Net.Mail.SmtpClient()
smtpclient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
Dim contype As New System.Net.Mime.ContentType("text/calendar")
contype.Parameters.Add("method", "REQUEST")
contype.Parameters.Add("name", "Meeting.ics")
Dim avCal As AlternateView = AlternateView.CreateAlternateViewFromString(str.ToString(), contype)
msg.AlternateViews.Add(avCal)
smtpclient.Send(msg)
Response.Write("ส่งสำเร็จ")
Catch ex As Exception
Response.Write(ex)
End Try