How can I send a reminders from ASP app to Outlook?

I have been tasked to figure out how to send reminders and notices from web-based ASP applications to a user's Outlook calendar. I saw it used on a web application (not sure if it was an ASP application) using a .vcs file. What is the best approach to accomplish this? Can someone point me to some resources that could help me figure this out?
okcuserAsked:
Who is Participating?
 
jarwConnect With a Mentor Commented:
Ok. They don't appear to do any configuration of the CDO.Message object at all. I would think then that your server may have its own SMTP server running locally and is capable of sending mail for you. Try commenting out all of the "mail.Configuration..." lines that set up the SMTP server and see what happens.

If you don't have an SMTP server configured, CDO should default to attempting to send the mail using the local server. Just like in the example you posted. They create the CDO.Message object, set the email properties, and call send without telling it anything about which email server to use.
0
 
jarwCommented:
I have been wanting to do something similar myself. You need to google on the iCalendar format to learn more about your options, but you can easily generate .ics files and provide links from your web pages that users can click to add events, attach the .ics file to an email so the recipient can open the attachment to add an item to the calendar, or I worked up another way which is really what I think is ideal. You embed the .ics information in the email and Outlook treats it as any other meeting request, so you can accept the invitation and have it added to your calendar.

I think there's still probably a better way to do this than I figured out, but it works for now. I have provided an ASP script that works for me. Hopefully you can borrow whichever parts you need and tweak it for your application. Make sure to change the variables at the top of the script to hold your email address and SMTP server before attempting to test the script.

~JW
<%
Option Explicit
 
Dim fso, file, filename, tmpName, startDate, endDate, uniqueID
Dim yourEmail, smtpServer
 
yourEmail = "youremail@somewhere.com"
smtpServer = "smtp.someserver.com"
 
Set fso = Server.CreateObject("Scripting.FileSystemObject")
 
' Get a temporary filename on the web server where we can write the iCalendar
' format file.
tmpName = fso.GetTempName() & ".ics"
filename = Server.MapPath(".") & "\" & tmpName
 
' Get the start and end dates of the event (GMT).
startDate = "2/14/2008 5:00:00 PM"
endDate = "2/14/2008 6:00:00 PM"
 
' Get a unique ID to assign to the calendar event.
uniqueID = FormatDateTime(Now()) & "-" & tmpName & "-@" &_
   Request.ServerVariables("SERVER_NAME")
 
Set file = fso.CreateTextFile(filename)
 
' Write the iCalendar file to the file system.
file.WriteLine "BEGIN:VCALENDAR"
file.WriteLine "PRODID:-//ASP iCalendar Test//My ASP App V1.0//EN"
file.WriteLine "VERSION:2.0"
file.WriteLine "METHOD:REQUEST"
file.WriteLine "BEGIN:VEVENT"
file.WriteLine "ORGANIZER:MAILTO:you@youremail.com"
file.WriteLine "DTSTART:" & FormatDateTime(startDate)
file.WriteLine "DTEND:" & FormatDateTime(endDate)
file.WriteLine "LOCATION:At the office"
file.WriteLine "TRANSP:OPAQUE"
file.WriteLine "SEQUENCE:0"
file.WriteLine "UID:" & uniqueID
file.WriteLine "DTSTAMP:" & FormatDateTime(Now())
file.WriteLine "DESCRIPTION:My calendar event test."
file.WriteLine "SUMMARY:Valentine's Day Party"
file.WriteLine "PRIORITY:5"
file.WriteLine "CLASS:PUBLIC"
file.WriteLine "BEGIN:VALARM"
file.WriteLine "TRIGGER:-PT15M"
file.WriteLine "ACTION:DISPLAY"
file.WriteLine "END:VALARM"
file.WriteLine "END:VEVENT"
file.WriteLine "END:VCALENDAR"
 
file.Close()
 
' Send the iCalendar file as an email attachment.
Dim mail
Set mail = CreateObject("CDO.Message")
 
' Configure to use an external mail server (2), supply its domain name or IP
' address (your.smtp.server), and tell it which port to use (usally 25).
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
mail.Configuration.Fields.Update()
 
' Set up the email message body.
mail.Subject = "A New Event for You!"
mail.From = "yourname@somewhere.com"
mail.To = yourEmail
mail.TextBody = "Here is your event reminder!"
 
' Prepare the file attachment (the iCalendar file).
Dim att
Set att = mail.AddAttachment(filename)
att.ContentClass = "urn:content-classes:calendarmessage"
att.Fields.Item("urn:schemas:mailheader:content-type") = "text/calendar; method=REQUEST; name=""invite.ics"""
att.Fields.Item("urn:schemas:mailheader:content-disposition") = ""
att.Fields.Item("urn:schemas:mailheader:content-transfer-encoding") = "8bit"
att.Fields.Update()
 
' Set the content type of the email and send it.
mail.Fields.Item("urn:schemas:mailheader:content-type") = "multipart/alternative"
mail.Fields.Update()
mail.Send()
 
' Cleanup the file.
fso.DeleteFile filename, True
 
Set mail = Nothing
Set file = Nothing
Set fso = Nothing
 
' Utility function for date/time formatting.
Public Function FormatDateTime(dateTime)
   FormatDateTime = _
      Year(dateTime) &_
      Right("0" & Month(dateTime), 2) &_
      Right("0" & Day(dateTime), 2) &_
      "T" &_
      Right("0" & Hour(dateTime), 2) &_
      Right("0" & Minute(dateTime), 2) &_
      Right("0" & Second(dateTime), 2) &_
      "Z"
End Function
%>

Open in new window

0
 
okcuserAuthor Commented:
JW,

This looks like a valid soltuion, but I'm not sure how to implement it using ASP. This looks like a Visual Basic solution. Help!

Thanks,

Tammi
0
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

 
jarwCommented:
This is an ASP page (classic ASP, not ASP.NET) written in VBScript. In my experience, this is how most ASP is coded. What language do you use?
0
 
okcuserAuthor Commented:
I'm using Visual Studio 6 to develop in ASP and we use some VBScript and some JavaScript also, but our ASP and VBScript doesn't look like yours. As a matter of fact, I had to comment out Option Expoicit and the dimming of the variables in order to get your code to even run.

I konw that right now we are using CDO to send emails. Our main email is on an Exchange server and it isn't local. I'm not quite sure what SMTP is or even if I can set it up here. Any ideas? Is there a way to do this using CDO?

Thanks so much,

Tammi
objMessage.Subject = "My Subject"
objMessage.To = ttail@cox.net
objMessage.From = ttail@cox.net	
objMessage.HTMLBody = HTML
objMessage.Send
set objMessage=Nothing
 
We build the body of the message into the variable HTML.

Open in new window

0
 
jarwCommented:
Interesting. That's the exact configuration I'm used to developing with. :)

For the SMTP server, you just set it to the domain name or IP address of your Exchange server. That's what we do here.
0
 
okcuserAuthor Commented:
If I comment out certain things like "Option Explicit" and the dimming of the variables, I can get it to run...however, I am crashign on the mail.Send() line. It is saying "failed to connect to server." Could there be a problem with our SMTP server not being local? Is there another way to do it without using SMTP?

Thanks again,

Tammi
0
 
jarwCommented:
Sorry, I'm not an expert on how the mail server stuff works. I know we use an Exchange server here and I put its address in the CDO configuration when sending mail. That's the line in my code that reads:

mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer

Another thing you could do is to go into your email client (e.g. - Microsoft Outlook) and look at the properties of your email account. If you can send email from your machine using the Exchange server, you should be able to do it with the code. Make sure the exact name for the Exchange server you have entered in your email client is the one you're trying to use in the code. If that doesn't work, you might try asking one of your system administrators (assuming you have access to one!) if there is some reason why the Exchange server wouldn't allow a script to send email through it.
0
 
okcuserAuthor Commented:
OK...let's try this...

Exactly which lines of code do I need to modify in order to use this script? For example from your code above, I modified lines 7 and 8, which declared yourEmail and smtpServer. What other lines need to be modified with our information?

Thanks,

Tammi
0
 
okcuserAuthor Commented:
One more thing...is this server-side script? Or is this code located in your global.asa file? If it is in the global.asa file, how do I call it from my web page?

Thanks again!

Tammi
0
 
jarwCommented:
Yes, you would only have to modify lines 7 & 8 with values appropriate for your environment. I can paste the exact code I posted above (after entering my email address and server in lines 7 & 8) into a file named "test.asp" and then browse to that file on my web server, causing the email reminder to be sent to my inbox.

I thought of some other things that might be causing you problems, so I tried it on a couple of other servers. On one server, it complained that the mail server could not relay for one of the recipient addresses. My guess is that the exchange server does not permit mail to be relayed from my test server. In other words, an admin on your exchange server probably has to allow your server to relay mail through it.

The other thing to take note of is that the script creates the calendar file on your web server in the same directory where the script runs. It also deletes this file after sending the email. If the user running the web page does not have permissions to create and delete this file, the script will fail. For example, if you access your website as the anonymous user, you will need to grant permissions to the IUSR_<machine_name> account to create and delete files in the directory where the script is run.

Those are a couple more ideas to try anyway.
0
 
okcuserAuthor Commented:
Ugh! This shouldn't be this hard...

I'm getting a general error:

     error '80040211'
     /tonersafety/moc_test.asp, line 92

     Where Line 92 = mail.Send()

I'm not sure what's killing it. I know we can route mail through the address the exchange admin gave me, and I am a local admin with admin privelages on our web server.

Am I missing a dll or something?
0
 
okcuserAuthor Commented:
I copied this simpler code from another source and it doesn't work either.

However, one that uses this line:

Set objCDOMail = Server.CreateObject("CDONTS.NewMail")

Does work. Could that be the problem? What is the difference between CDO and CDONTS?
<% 
'Dimension variables 
Dim objCDOSYSCon , objCDOSYSMail, Body  
'Create the e-mail server object 
Set objCDOSYSMail = Server.CreateObject("CDO.Message") 
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration") 
'Out going SMTP server 
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "forwarder.mail.xerox.com" 
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 
objCDOSYSCon.Fields.Update 
 
'Update the CDOSYS Configuration 
Set objCDOSYSMail.Configuration = objCDOSYSCon 
 
objCDOSYSMail.From = "tammi.cole@xerox.com" 
objCDOSYSMail.To = "tammi.cole@xerox.com" 
objCDOSYSMail.Subject = "Your Subject" 
 
Body = "Dear " + "User"+ ","  
Body = Body + " <html>" 
Body = Body + " <body>" 
Body = Body + "<p>Your Mail script is working fine." 
Body = Body + "...</p> " 
Body = Body + "</body></html> " 
 
objCDOSYSMail.HTMLBody = Body 
objCDOSYSMail.Send 
 
'Close the server mail object 
Set objCDOSYSMail = Nothing 
Set objCDOSYSCon = Nothing 
Response.Write("Your mail was sent") 
%>

Open in new window

0
 
jarwCommented:
What type of server/OS are you running this on? That is which version of Windows and IIS?

CDONTS.NewMail is the object that used to be commonly used for sending email from ASP. It has been replaced by CDOSYS, which is what we're trying to use here. CDOSYS must be available to you, or you would have gotten an error well before the call to "Send".
0
 
okcuserAuthor Commented:
Web Server is Windows Server 2003 Standard Edition and IIS 6.0.

I know we're using CDO, I just don't know why your script is stalling. I looked a couple of other scripts from our website this morning where we are attaching excel spreadsheets and word documents using the CDO.Message method and they work. I copied one below. Maybe it can help us figure out what our setup doesn't like about your script?

The CDONTS method I used earlier worked too. I could be mistaken, but it seems like it might have something to do with the way the .ics file is attached....

Thanks,

Tammi
<%
Select Case Request.Form("Action")
	Case "Export"
			Dim objWord
			
			Session("sysMsg")="INTERNAL LIST EMAILED-PRINT FROM WORD"	
			
			Set objWord = CreateObject("Word.Application")
			objWord.Application.Visible = true
			Set WordDoc = objWord.Documents.Add("C:\phonelistbig2.dot")
 
			With WordDoc
				.Bookmarks("CurDate").Range.InsertAfter Cstr(Date())
 
				Dim ltr
				Dim c,r
			
				c = 1
				r = 0
				ltr = "*"
				Set rs = objConn.Execute ("SELECT * FROM tblOKCPeople ORDER BY LastName, FirstName")
				Do While Not rs.EOF
					If rs("LastName")<>"" and rs("FirstName")<>"" Then
						If left(rs("LastName"),1) <> ltr then
							r=r+1
							ltr = left(rs("LastName"),1)
						End If
						Select case c
							case 1
								If r > 67 Then
									c = 2
									r = 1
								End If
							case 2
								If r > 67 Then 
									c = 3
									r = 1
								End If
							case 3
								If r > 37 Then
									Response.Write "Too many rows."
									c = 0
								End If
						End Select
						If c <> 0 Then
							.Tables(2).Cell(r, c).Range.InsertAfter rs("LastName") & ", " & rs("FirstName") & chr(9) & rs("Ext")
						End If
					End If
					r = r + 1
					rs.MoveNext
				Loop
				rs.close
								
				'******************
				'Insert Key Numbers
				'******************
				Set rs = objConn.Execute ("SELECT * FROM tblKeyGroups ORDER BY tblKeyGroups.Description ASC")
				Do While Not rs.EOF
						Set rs2 = objConn.Execute ("SELECT * FROM tblKeyNumbers WHERE KeyGroupID = " & rs("KeyGroupID") & " ORDER BY Description ASC")
						If not (rs2.eof and rs2.bof) then
							Select case c
								case 1
									If r > 67 Then
										c = 2
										r = 1
									End If
								case 2
									If r > 67 Then 
										c = 3
										r = 1
									End If
								case 3
									If r > 37 Then
										Session("sysMsg")="Too many rows"	
										c = 0
									End If
							End Select
							If c <> 0 Then
								r = r + 2
								.Tables(2).Cell(r, c).Range.InsertAfter rs("Description")
								.Tables(2).Cell(r, c).Range.Font.bold = true
							End If
							Do While Not rs2.eof
								If rs2("Description") <> "" Then
									r = r + 1
									Select case c
										case 1
											If r > 67 Then
												c = 2
												r = 1
											End If
										case 2
											If r > 67 Then 
												c = 3
												r = 1
											End If
										case 3
											If r > 37 Then
												Session("sysMsg")="Too many rows"	
												c = 0
											End If
									End Select
									If c <> 0 Then
										.Tables(2).Cell(r, c).Range.InsertAfter rs2("Description") & chr(9) & rs2("Number")
									End If									
								End If
								rs2.movenext
							Loop
						End If
						rs2.Close
					rs.MoveNext
				Loop
				rs.Close
			
				.SaveAs "c:\PhoneList.doc"
				.Close
 
			End With
			
			Set objWord = CreateObject("Word.Application") 
			Set WordDoc = objWord.Documents.Add("c:\PhoneList.doc")
			objWord.Application.Visible = true
			FileName = "c:\PhoneList.doc"
			
			objWord.Quit
			Set WordDoc= Nothing     
			Set objWord = Nothing
			
			cs_Email = Request.Form ("txtEmail")
			
			HTML = HTML & "<HTML>"
			HTML = HTML & "<HEAD>"
			HTML = HTML & "<TITLE>Phone List</TITLE>"
			HTML = HTML & "</HEAD>"
			HTML = HTML & "<BODY>"
			HTML = HTML & "Attached is the current Phone List as of " & Date() & "."
			HTML = HTML & "</BODY>"
			HTML = HTML & "</HTML>"
 
    		Set objMessage = CreateObject("CDO.Message") 
			objMessage.Subject = "Oklahoma City MFG Phone List"
			objMessage.To = cs_Email
			objMessage.From = cs_Email		
			objMessage.HTMLBody = HTML
			
			FilePath_Name = FileName
			objMessage.AddAttachment FilePath_Name
 
			objMessage.Send
			set objMessage=Nothing 
	End Select	
%>

Open in new window

0
 
okcuserAuthor Commented:
*party dance*

That worked!  Thank you so very much for sticking it out with me :)

Tammi
0
 
okcuserAuthor Commented:
This person was very patient and knowledgeable and I appreciate them sticking it out to help me find a solution.
0
 
jarwCommented:
Great! I'm glad it worked out. The coding part is usually easy compared to all of the different server configurations it might be running on. :)

Good luck!

~JW
0
All Courses

From novice to tech pro — start learning today.