I am using the following code to send an outlook appointment using system.net.mail The code works perfectly and i am able to receive the appointment. But the problem is i can't figure out how to assign the appointment start date or end date
'Str.AppendLine(String.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", DateTime.Now)) Str.AppendLine(String.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow)) Str.AppendLine(String.Format("DTEND:{0:yyyyMMddTHHmmssZ}", DateTime.Now.AddHours(3)))
1) How do i set the UTC, as if i assign current date now it's always +8. can i just provide a date time without using UTC. 2) And how do i specify the date time in the code. cause right now it use DateTime.Now then works. But manual assign not working
The complete code as below
Dim testMessage As New System.Net.Mail.MailMessage Dim fromAddress As New System.Net.Mail.MailAddress("[email protected]") Dim objSmtpClient As New SmtpClient(smtpIP, 25) Dim mailAttachment As Attachment Dim iserror As Boolean = False Try testMessage.From = fromAddress testMessage.To.Add("[email protected]") testMessage.Subject = "Training Scheduled" testMessage.Priority = MailPriority.Normal testMessage.Body = "Test" testMessage.IsBodyHtml = False Dim Str As New System.Text.StringBuilder() 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)) 'Str.AppendLine(String.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", DateTime.Now)) Str.AppendLine(String.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow)) Str.AppendLine(String.Format("DTEND:{0:yyyyMMddTHHmmssZ}", DateTime.Now.AddHours(3))) 'Str.AppendLine(String.Format("DTEND:{0:yyyyMMddTHHmmssZ}", DateTime.Now)) 'Str.AppendLine("LOCATION: " + Me.Location) Str.AppendLine(String.Format("UID:{0}", Guid.NewGuid())) Str.AppendLine(String.Format("DESCRIPTION:{0}", testMessage.Body)) Str.AppendLine(String.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", testMessage.Body)) Str.AppendLine(String.Format("SUMMARY:{0}", testMessage.Subject)) Str.AppendLine(String.Format("ORGANIZER:MAILTO:{0}", testMessage.From.Address)) Str.AppendLine(String.Format("ATTENDEE;CN=""{0}"";RSVP=TRUE:contact{1}", testMessage.[To](0).DisplayName, testMessage.[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 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) testMessage.AlternateViews.Add(avCal) objSmtpClient.Send(testMessage) Catch ex As Exception 'MessageBox.Show(ex.ToString) iserror = True Finally objSmtpClient = Nothing 'alertMessage = Nothing fromAddress = Nothing End Try