Imports System.Net.Mail
Imports System.Net
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim schLocation As String = "Conference Room"
Dim schSubject As String = "Business visit discussion"
Dim schDescription As String = "Schedule description"
Dim schBeginDate As System.DateTime = Convert.ToDateTime("18/2/2017 10:00:00 PM")
Dim schEndDate As System.DateTime = Convert.ToDateTime("18/2/2017 11:00:00 PM")
'PUTTING THE MEETING DETAILS INTO AN ARRAY OF STRING
Dim contents As [String]() = {"BEGIN:VCALENDAR", "PRODID:-//Flo Inc.//FloSoft//EN", "BEGIN:VEVENT", "DTSTART:" + schBeginDate.ToUniversalTime().ToString("yyyyMMdd\THHmmss\Z"), "DTEND:" + schEndDate.ToUniversalTime().ToString("yyyyMMdd\THHmmss\Z"), Convert.ToString("LOCATION:") & schLocation, _
Convert.ToString("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:") & schDescription, Convert.ToString("SUMMARY:") & schSubject, "PRIORITY:3", "END:VEVENT", "END:VCALENDAR"}
System.IO.File.WriteAllLines(Server.MapPath("Sample.ics"), contents)
SendMail()
End Sub
Public Sub SendMail()
Dim FromName As String = "TestNameFrom"
Dim FromEmail As String = "[email protected]"
Dim ToName As String = "TestNameTo"
Dim ToEmail As String = "[email protected]"
Dim smtp As System.Net.Mail.SmtpClient = New SmtpClient()
smtp.EnableSsl = False
Dim mailMessage As New System.Net.Mail.MailMessage()
mailMessage.From = New System.Net.Mail.MailAddress(FromEmail, FromName)
mailMessage.[To].Add(New System.Net.Mail.MailAddress(ToEmail, ToName))
mailMessage.Subject = "Outlook calendar as attachment"
mailMessage.Body = "This is a test message."
Dim mailAttachment As New Attachment(Server.MapPath("Sample.ics"))
mailMessage.Attachments.Add(mailAttachment)
smtp.Send(mailMessage)
Response.Write("ส่งสำเร็จ")
End Sub
End Class
'Add the attachment, specify it is a calendar file.
Dim attachment As System.Net.Mail.Attachment = System.Net.Mail.Attachment.CreateAttachmentFromString(iCal, New ContentType("text/calendar"))
attachment.TransferEncoding = TransferEncoding.Base64
attachment.Name = "EventDetails.ics"
'not visible in outlook
message.Attachments.Add(attachment)
sendMailMessage(message)