home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / tlcTest5.aspx.vb < prev    next >
Text File  |  2014-11-01  |  5KB  |  108 lines

  1. ∩╗┐Imports Microsoft.VisualBasic
  2. Imports System.Net.Mail
  3. Imports System.IO
  4. Imports AspNetMaker7_tfpssnet
  5.  
  6. Partial Class tlcTest5
  7.     Inherits System.Web.UI.Page
  8.  
  9.     Public StartDate As DateTime
  10.     Public EndDate As DateTime
  11.     Public StartTime As String
  12.     Public EndTime As String
  13.     Public Subject As String
  14.     Public Summary As String
  15.     Public Location As String
  16.     Public AttendeeName As String
  17.     Public AttendeeEmail As String
  18.     Public OrganizerName As String
  19.     Public OrganizerEmail As String
  20.  
  21.     ''' <summary>
  22.     ''' Compiles an Outlook Calendar file and Emails it to the Person selected as an attachment
  23.     ''' </summary>
  24.     ''' <param name="subject"></param>
  25.     ''' <param name="location"></param>
  26.     ''' <param name="description"></param>
  27.     ''' <param name="startDate"></param>
  28.     ''' <param name="enddate"></param>
  29.     ''' <param name="startTime">Leave NULL for ALL Day</param>
  30.     ''' <param name="endTime">Leave NULL for ALL Day</param>
  31.     ''' <param name="from">EMAIL Address Sent FROM</param>
  32.     ''' <param name="to">EMAIL Address Sent TO</param>
  33.     ''' <remarks></remarks>
  34.     Public Shared Sub VCSEmailed(ByVal subject As String, ByVal location As String, ByVal description As String, ByVal startDate As DateTime, ByVal enddate As DateTime, ByVal startTime As String, ByVal endTime As String, ByVal from As String, ByVal [to] As String)
  35.         Dim file As New System.Text.StringBuilder
  36.         If String.IsNullOrEmpty(startTime) And String.IsNullOrEmpty(endTime) Then
  37.             startTime = "0700"
  38.             endTime = "1900"
  39.         End If
  40.         Dim description2 As String = description
  41.  
  42.         description = description.Replace(Chr(13), "\n")
  43.         description = description.Replace(Chr(10), "\n")
  44.         With file
  45.             .AppendLine("BEGIN:VCALENDAR")
  46.             .AppendLine("PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN")
  47.             .AppendLine("VERSION:1.0")
  48.             .AppendLine("BEGIN:VEVENT")
  49.             .AppendLine("ORGANIZER:MAILTO:" & from)
  50.             .AppendLine("CATEGORIES:CRM Appointment")
  51.             .AppendLine("DTSTART:" & Year(startDate) & Right("0" & Month(startDate), 2) & Right("0" & Day(startDate), 2) & "T" & startTime & "00CST")
  52.             .AppendLine("DTEND:" & Year(enddate) & Right("0" & Month(startDate), 2) & Right("0" & Day(startDate), 2) & "T" & endTime & "00CST")
  53.             .AppendLine("UID:1")
  54.             .AppendLine("LOCATION:" & location)
  55.             .AppendLine("DESCRIPTION:" & description)
  56.             .AppendLine("SUMMARY:" & subject)
  57.             .AppendLine("PRIORITY:1")
  58.             .AppendLine("END:VEVENT")
  59.             .AppendLine("END:VCALENDAR")
  60.         End With
  61.  
  62.         Dim filename As String = " Appointment sent from CRM on " & Now.Day.ToString & "-" & Now.Month.ToString & "-" & Now.Year.ToString
  63.         Dim filePath As String = String.Empty
  64.         Dim path As String = HttpContext.Current.Server.MapPath("\db\")
  65.         filePath = path + filename & ".ics"
  66.         Dim writer = New StreamWriter(filePath)
  67.         writer.Write(file)
  68.         writer.Close()
  69.         Dim attach As New Attachment(filePath)
  70.         SendMail(from, [to], subject, description2, attach)
  71.         System.IO.File.Delete(filePath)
  72.     End Sub
  73.  
  74.     Private Shared Sub SendMail(ByVal from As String, ByVal [to] As String, ByVal subject As String, ByVal body As String, ByVal attachment As Attachment)
  75.         Dim mail As New MailMessage(from, [to], subject, body)
  76.         mail.Bcc.Add(from)
  77.         If String.IsNullOrEmpty(attachment.Name) Then
  78.         Else
  79.             mail.Attachments.Add(attachment)
  80.         End If
  81.  
  82.         Dim smtp As New SmtpClient("server6")
  83.         smtp.Send(mail)
  84.         mail.Dispose()
  85.  
  86.     End Sub
  87.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  88.  
  89.         ' Send the calendar message to the attendee
  90.  
  91.         StartDate = "2/23/2011"
  92.         EndDate = "2/23/2011"
  93.         StartTime = "080000"
  94.         EndTime = "090000"
  95.         Subject = "Test Subject"
  96.         Summary = "Test Summary"
  97.         Location = "Test Location"
  98.         AttendeeName = "Tony Clayton"
  99.         AttendeeEmail = "tony.clayton@suddenlink.net"
  100.         OrganizerName = "prodservices"
  101.         OrganizerEmail = "productionservices@tfc.org"
  102.  
  103.         Call VCSEmailed(Subject, Location, "Test Description", StartDate, EndDate, StartTime, EndTime, OrganizerEmail, AttendeeEmail)
  104.  
  105.     End Sub
  106.  
  107. End Class
  108.