bdinnocenzo
Active member
I cobbled together the code below in an attempt to send a calendar request via email. Even though I've set the Content-Type to "text/calendar" and formed the VCalendar "body" correctly (I think) the email shows up as text with my header for Content-Type as well as another set to "text/plain". I've searched this forum as well as the web and have found some stuff, but it still has not been able to lead me to my error. I'm thinking this should not be as hard as it is...am I wrong?
Here's the code:
When this shows up in my mail box, either Outlook 2007 or my same account accessed through the web, it is just a text message. Here's what comes through:
Any clues? Thanks,
-Bill
Here's the code:
VB.NET:
Dim SMTP As New SmtpClient
Dim m As New MailMessage
Dim Invite As New VCalendar
Dim Body As String = ""
With Invite
.summary = txtBody.Text
.location = txtLocation.Text
.start_day = CInt(dtpStartDate.Value.ToString("dd"))
.start_month = CInt(dtpStartDate.Value.ToString("MM"))
.start_year = CInt(dtpStartDate.Value.ToString("yyyy"))
.end_day = CInt(dtpEndDate.Value.ToString("dd"))
.end_month = CInt(dtpEndDate.Value.ToString("MM"))
.end_year = CInt(dtpEndDate.Value.ToString("yyyy"))
.start_hour = CInt(dtpStartTime.Value.ToString("hh"))
.start_minute = CInt(dtpStartTime.Value.ToString("mm"))
.start_second = 0
.end_hour = CInt(dtpEndTime.Value.ToString("hh"))
.end_minute = CInt(dtpEndTime.Value.ToString("mm"))
.end_second = 0
.method = "REQUEST"
End With
FromMail = "info@somesite.com"
Body = CreateCalendarRecord(Invite)
SMTP.Host = "mail.somesite.com"
SMTP.Port = 25
m.From = New MailAddress(FromMail, "Invite")
m.To.Add(txtRequired.Text)
If txtOptional.Text.Length > 0 Then
m.To.Add(txtOptional.Text)
End If
m.Subject = "Invite: " & txtSubject.Text
m.IsBodyHtml = False
m.Priority = MailPriority.Normal
m.Body = Body ' & vbNewLine & "*~*~*~*~*~*~*~*~*~*" & _
vbNewLine & txtBody.Text
[B]m.Headers.Add("Content-Type", "text/calendar; method=REQUEST;charset=""UTF-8""")[/B]
m.Headers.Add("Content-Transfer-Encoding", "7bit")
For i = 0 To m.Headers.Count - 1
Debug.Print(i.ToString & " - " & m.Headers.Keys(i).ToString & ": " & _
m.Headers.Item(i).ToString)
Next
SMTP.DeliveryMethod = SmtpDeliveryMethod.Network
Try
SMTP.Send(m) ' Send it
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Function CreateCalendarRecord(ByVal calEvent As VCalendar) As String
Dim calRecord As String = ""
calRecord = "BEGIN:VCALENDAR" & vbNewLine
calRecord &= "PRODID:-//CalendarThing//EN" + vbNewLine
calRecord &= "METHOD:" & calEvent.method & vbNewLine
calRecord &= "VERSION:2.0" & vbNewLine
calRecord &= "BEGIN:VEVENT" & vbNewLine
calRecord &= "ORGANIZER:mailto:" & FromMail & vbNewLine
calRecord &= "ATTENDEE;RSVP=YES:mailto:" & txtRequired.Text & vbNewLine
calRecord &= "DTSTAMP:" & Now.Year.ToString("0000") _
& Now.Month.ToString("00") & Now.Day.ToString("00") _
& "T" & Now.Hour.ToString("00") & Now.Minute.ToString("00") _
& Now.Second.ToString("00") & "Z" & vbNewLine
calRecord &= "DTSTART:" & calEvent.start_year.ToString("0000") & _
calEvent.start_month.ToString("00") & _
calEvent.start_day.ToString("00") & _
"T" & calEvent.start_hour.ToString("00") & _
calEvent.start_minute.ToString("00") & _
calEvent.start_second.ToString("00") & "Z" & vbNewLine
calRecord &= "DTEND:" & calEvent.end_year.ToString("0000") & _
calEvent.end_month.ToString("00") & _
calEvent.end_day.ToString("00") & _
"T" & calEvent.end_hour.ToString("00") & _
calEvent.end_minute.ToString("00") & _
calEvent.end_second.ToString("00") & "Z" & vbNewLine
calRecord &= "LOCATION:" & calEvent.location & vbNewLine
calRecord &= "SUMMARY:" & calEvent.summary & vbNewLine
calRecord &= "DESCRIPTION:" & "Just a test for now" & vbNewLine
' Calculate unique ID based on current DateTime and its MD5 hash
Dim strHash As String
strHash = ""
For Each b As Byte In (New MD5CryptoServiceProvider()). _
ComputeHash(System.Text.Encoding.Default.GetBytes( _
DateTime.Now.ToString()))
strHash &= b.ToString("X2")
Next
calRecord &= "UID:" & strHash & vbNewLine
calRecord &= "STATUS:CONFIRMED" & vbNewLine
calRecord &= "END:VEVENT" & vbNewLine
calRecord &= "END:VCALENDAR" ' & vbNewLine ' DO I NEED THIS LAST vbNewLine?
Debug.Print(calRecord)
Return calRecord
End Function
When this shows up in my mail box, either Outlook 2007 or my same account accessed through the web, it is just a text message. Here's what comes through:
BEGIN:VCALENDAR
PRODID:-//CalendarThing//EN
METHOD:REQUEST
VERSION:2.0
BEGIN:VEVENT
ORGANIZER:mailto:info@somesite.com
ATTENDEE;RSVP=YES:mailto:bill@somesite.com
DTSTAMP:20091119T103615Z
DTSTART:20091119T103600Z
DTEND:20091119T113600Z
LOCATION:My Cyberspace Office
SUMMARY:This is the body of the invite...
DESCRIPTION:Just a test for now
UID:C86FD1CD55136D79A5C884071008D650
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR
PRODID:-//CalendarThing//EN
METHOD:REQUEST
VERSION:2.0
BEGIN:VEVENT
ORGANIZER:mailto:info@somesite.com
ATTENDEE;RSVP=YES:mailto:bill@somesite.com
DTSTAMP:20091119T103615Z
DTSTART:20091119T103600Z
DTEND:20091119T113600Z
LOCATION:My Cyberspace Office
SUMMARY:This is the body of the invite...
DESCRIPTION:Just a test for now
UID:C86FD1CD55136D79A5C884071008D650
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR
Any clues? Thanks,
-Bill
Last edited: