Got it to work
After a lot of trial and error, I finally got this to work:
This part was correct:
Dim email As New MailMessage
email.To.Add(New MailAddress("(e-mail address removed)", "John Doe"))
Dim from As New MailAddress("(e-mail address removed)", "Sender Doe")
email.From = from
email.Subject = subject
email.Headers.Add("Content-Type", "text/calendar; method=REQUEST; charset=US-ASCII")
email.Body = "BEGIN:VCALENDAR..."
Dim SmtpMail As New SmtpClient()
SmtpMail.Host = "mail server"
SmtpMail.Send(email)
The issue was with the vCalendar. If the syntax isn't correct, then it comes through as an empty email. For me, the problem was I left out the UID.
The troubleshoot, I attached the vCalendar to an email. When trying to open the attached file, Outlook generated an error. I saved the file locally, and made changes until I could import.
Here is the StringBuilder that I am now using to generate the vCalendar
parameters passed into the function:
(ByVal toAddress As String, _
ByVal toName As String, _
ByVal fromAddress As String, ByVal fromName As String, _
ByVal subject As String, ByVal body As String, _
ByVal location As String, ByVal startDate As DateTime, _
ByVal endDate As DateTime, ByVal setReminder As Boolean, _
ByVal reminderDuration As TimeSpan)
Private dtFormat As String = "yyyyMMddTHHmmssZ"
Dim sb As New StringBuilder()
sb.AppendLine("BEGIN:VCALENDAR")
sb.AppendLine("PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN")
sb.AppendLine("VERSION:2.0")
sb.AppendLine("METHOD
UBLISH")
sb.AppendLine("BEGIN:VEVENT")
sb.AppendFormat("ATTENDEE;CN=""{0}"";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:{1}" & vbCrLf, _toName, _toAddress)
sb.AppendFormat("ORGANIZER:MAILTO:{0}" & vbCrLf, _fromAddress)
sb.AppendFormat("DTSTART:{0}" & vbCrLf, _startDate.ToUniversalTime.ToString(dtFormat))
sb.AppendFormat("DTEND:{0}" & vbCrLf, _endDate.ToUniversalTime.ToString(dtFormat))
sb.AppendFormat("LOCATION:{0}" & vbCrLf, _location)
sb.AppendLine("TRANSP:OPAQUE")
sb.AppendLine("SEQUENCE:0")
sb.AppendFormat("UID:{0}" & vbCrLf, DateTime.Now.Ticks.ToString("x") & "-" _
& _fromAddress & Guid.NewGuid().ToString)
sb.AppendFormat("DTSTAMP:{0}" & vbCrLf, DateTime.Now.ToUniversalTime.ToString(dtFormat))
sb.AppendFormat("DESCRIPTION:{0}" & vbCrLf, _body)
sb.AppendFormat("SUMMARY:{0}" & vbCrLf, _subject)
sb.AppendFormat("PRIORITY:{0}" & vbCrLf, 5)
sb.AppendLine("X-MICROSOFT-CDO-IMPORTANCE:1")
sb.AppendLine("CLASS
UBLIC")
If _setReminder Then
sb.AppendLine("BEGIN:VALARM")
sb.AppendFormat("TRIGGER
{0}DT{1}H{2}M" & vbCrLf, _reminderDuration.Days, _
_reminderDuration.Hours, _reminderDuration.Minutes)
sb.AppendLine("ACTION
ISPLAY")
sb.AppendLine("DESCRIPTION:Reminder")
sb.AppendLine("END:VALARM")
End If
sb.AppendLine("END:VEVENT")
sb.AppendLine("END:VCALENDAR")
Vlad, that for pulling me on the right track!!
Josh