Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I use the code below to send invitations from my web calendar to other web users. I invitations get very good to outlook users and outlook web version, they have the accept and deny buttons and so on. And the message is in the mail body too. The problem that when I send it to Gmail users, the invitation only appear as attachment, there is no "accept" or deny buttons and so on. In the message body there is only the html I send as "description".

 

Can I send this invitations from my dot net web page and make it appear the same in Gmail and outlook?

 

i tried for houes every thing i know with out success... does any body have idea?

 

Thanks.

 

my code-

Public Shared Function sendOutlookInvitationViaICSFile(objApptEmail As eAppointmentMail) As String

Try

Dim sc As New SmtpClient("XXXXXXXXXXXXXXX")

 

Dim msg As New System.Net.Mail.MailMessage()

msg.From = New MailAddress("XXXXXXXXXXXXXX", "XXXXXXXXXXXXXX")

 

msg.[To].Add(New MailAddress(objApptEmail.Email, objApptEmail.Name))

msg.Subject = objApptEmail.Subject

msg.IsBodyHtml = True

 

Dim ct As New System.Net.Mime.ContentType("text/calendar")

ct.Parameters.Add("method", "REQUEST")

ct.Parameters.Add("charset", "UTF-8")

 

Dim avCal As AlternateView = AlternateView.CreateAlternateViewFromString(buildICSText(objApptEmail), ct)

avCal.TransferEncoding = Mime.TransferEncoding.Base64

 

msg.AlternateViews.Add(avCal)

 

Dim nc As New Net.NetworkCredential("shoresh", "15128511")

 

' sc.EnableSsl = True

sc.Credentials = nc

 

Try

sc.Send(msg)

Return True

Catch ex As Exception

 

Return ex.Message

End Try

Catch ex As Exception

Return ex.Message

End Try

 

End Function

 

Private Shared Function buildICSText(objApptEmail As eAppointmentMail) As String

Dim str As New StringBuilder()

str.AppendLine("BEGIN:VCALENDAR")

str.AppendLine("PRODID:-//" & Convert.ToString(objApptEmail.Email))

str.AppendLine("VERSION:2.0")

str.AppendLine("CALSCALE:GREGORIAN")

str.AppendLine("METHOD:REQUEST")

str.AppendLine("BEGIN:VEVENT")

str.AppendLine(String.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", objApptEmail.StartDate.ToUniversalTime().ToString("yyyyMMdd\THHmmss\Z")))

str.AppendLine(String.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", (objApptEmail.EndDate - objApptEmail.StartDate).Minutes.ToString()))

str.AppendLine(String.Format("DTEND:{0:yyyyMMddTHHmmssZ}", objApptEmail.EndDate.ToUniversalTime().ToString("yyyyMMdd\THHmmss\Z")))

str.AppendLine("ORGANIZER:mailto:meni88@gmail.com")

str.AppendLine("LOCATION:" & Convert.ToString(objApptEmail.Location))

str.AppendLine(String.Format("UID:{0}", Guid.NewGuid()))

str.AppendLine(String.Format("DESCRIPTION:{0}", objApptEmail.Body))

str.AppendLine(String.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", objApptEmail.Body))

str.AppendLine(String.Format("SUMMARY:{0}", objApptEmail.Subject))

str.AppendLine(String.Format("ORGANIZER:MAILTO:{0}", objApptEmail.Email))

str.AppendLine(String.Format("ATTENDEE;CN=""{0}"";RSVP=TRUE:mailto:{1}", objApptEmail.Name, objApptEmail))

str.AppendLine("BEGIN:VALARM")

str.AppendLine("TRIGGER:-PT15M")

str.AppendLine("ACTION:DISPLAY")

str.AppendLine("DESCRIPTION:Reminder")

str.AppendLine("END:VALARM")

str.AppendLine("TRANSP:OPAQUE")

str.AppendLine("END:VEVENT")

str.AppendLine("END:VCALENDAR")

 

Return str.ToString()

End Function

Posted

it is possible. Every mail system has it's "invite" function. the problem with my code was the format of the "tags", in Gmail you have to be very accurate in the syntax. OUTLOOK is more forgivable.

Now it is working for me in both platforms.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...