Mark Drelinger
asked on
vb script in classic to create vcard file and send email.
add function to classic asp page with vb script.
Is it possible to save a file temporarily and then attach it to an email in vbscript ?
If I split the code below into two distinct pages, both functions work. I can create the Vcard file and it opens to the user. Or I can create the email.
But I want to add the vcard file to the email. Is this possible ?
Is it possible to save a file temporarily and then attach it to an email in vbscript ?
If I split the code below into two distinct pages, both functions work. I can create the Vcard file and it opens to the user. Or I can create the email.
But I want to add the vcard file to the email. Is this possible ?
<%
if (cStr(Request("SubmitHere")) <> "") Then
Dim DTSTART, DTEND, SUMMARY, LOCATION, EVENT_DESCRIPTION, PRIORITY, UID, CalendarEvent
DTSTART = DateAdd("h",+5, (rsSaleCallDataNewID.Fields.Item("FollowupDate").Value))
DTEND = DateAdd("h",+5, (rsSaleCallDataNewID.Fields.Item("FollowupDate").Value))
DTSTART = Right("0000" & Year(DTSTART), 4) & _
Right("00" & Month(DTSTART), 2) & _
Right("00" & Day(DTSTART), 2) & _
"T13000" & _
"Z"
DTEND = Right("0000" & Year(DTEND), 4) & _
Right("00" & Month(DTEND), 2) & _
Right("00" & Day(DTEND), 2) & _
"T130000" & _
"Z"
SUMMARY = (rsSaleCallDataNewID.Fields.Item("VisitType").Value)
LOCATION = (rsSaleCallDataNewID.Fields.Item("Company").Value)
EVENT_DESCRIPTION = (rsSaleCallDataNewID.Fields.Item("Comments").Value)
PRIORITY = "0"
UID = (rsSaleCallDataNewID.Fields.Item("ID").Value)
CalendarEvent = "BEGIN:VCALENDAR" & vbCrlf & _
"VERSION:1.0" & vbCrlf & _
"BEGIN:VEVENT" & vbCrlf & _
"DTSTART:" & DTSTART & vbCrlf & _
"DTEND:" & DTEND & vbCrlf & _
"SUMMARY;ENCODING=QUOTED-PRINTABLE:" & SUMMARY & vbCrlf & _
"DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" & StripLineBreaks(EVENT_DESCRIPTION) & vbCrlf & _
"LOCATION;ENCODING=QUOTED-PRINTABLE:" & LOCATION & vbCrlf & _
"UID:" & UID & vbCrlf & _
"PRIORITY:" & PRIORITY & vbCrlf & _
"END:VEVENT" & vbCrlf & _
"END:VCALENDAR" & vbCrlf
Response.ContentType = "text/x-vCalendar"
Response.AddHeader "Content-Disposition", "filename=CalendarEvent.vcs;"
Response.Write CalendarEvent
Response.End
Set objCDO = Server.CreateObject("CDONTS.NewMail")
objCDO.From = Request.Form("varFrom")
objCDO.To = Request.Form("varTo")&";"&Request.Form("TeamAlerts")
objCDO.CC = Request.Form("varCC")
objCDO.BCC = Request.Form("varTeamLeader")
'objCDO.AttachFile filename
'objCDO.AttachFile "ContactManagementActivityEditVCal.asp?" & Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "varVcal=yes&var_SaleCall_ID=" & rsSaleCallDataNewID.Fields.Item("ID").Value
objCDO.Subject = "An Activity was Created by "&Request.Form("varCreatedBy")&" for " &Request.Form("varCompanyName")
objCDO.Body = "A new Activity for "&Request("varCompanyName")&" was Created by "&Request("varCreateBy")&"."&vbcrlf&"Dept: "&Request("varDepartment")&". Activity Purpose: "&Request("varVisitType")&"."&vbcrlf&"Activity Date: "&Request("varActivityDate")&". "&"Contact: "&Request("varContactName")&"."&vbcrlf&"Contact Phone: "&Request("varPhone")&"."&vbcrlf&vbcrlf&"Comments: "&Request("varComments")&"."&vbcrlf&vbcrlf&"Message: "&Request("varMessage")&"."&vbcrlf&vbcrlf&"To view this from a Mobile Device, click here: https://www.team-cbr.com/webapps2.0/palmcustomeractivityviewstep2.asp?var_table_id="&Request("varID")&vbcrlf&"To view this from a PC, click here: https://www.team-cbr.com/WebApps2.0/ContactManagementActivityEdit.asp?var_SaleCall_ID="&Request("varID")
objCDO.Send()
Set objCDO = Nothing
Response.Redirect("ContactManagementSearch.asp")
'Response.Redirect("ContactManagementUpdateBasic.asp?var_Table_ID=" & rsCustomerDataFull.Fields.Item("Table_ID").Value & "&varCustNumber=" & rsCustomerDataFull.Fields.Item("JDIS_ID").Value)
End If
%>
ASKER
so how did you make the connection between "filename=CalendarEvent.vc s" and then "vcard.asp?event=123" ?
ASKER
the first section creates the vcard, but it opens it within the browser (ie open or save as).
Can we save it into a temp file and then reference it in the next step ?
Can we save it into a temp file and then reference it in the next step ?
You can do that too, but in your add attachment code, it should grab that as a file. But I think something is missing, If you surf to it you should see an instant download. I will try and sift through my old files.
If you want to save it to file you can do that.
Some old questions on this subject
https://www.experts-exchange.com/questions/27055665/ASP-Form-Submit-with-File-attachment-from-memory.html
https://www.experts-exchange.com/questions/28218900/Generate-an-automatic-email-response-with-an-option-to-add-an-attachment.html
I looked up some old code I have stored in an archive.
That bit of code should force download and in your case, create the attachment. I am short of time right now and will come back to this later for you to try and recreate with your vcard example.
I think the key items are
If you want to save it to file you can do that.
Some old questions on this subject
https://www.experts-exchange.com/questions/27055665/ASP-Form-Submit-with-File-attachment-from-memory.html
https://www.experts-exchange.com/questions/28218900/Generate-an-automatic-email-response-with-an-option-to-add-an-attachment.html
I looked up some old code I have stored in an archive.
If objFSO.FileExists(strAbsFile) Then
Set objFile = objFSO.GetFile(strAbsFile)
'-- first clear the response, and then set the appropriate headers
Response.Clear
'-- the filename you give it will be the one that is shown
' to the users by default when they save
Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name
Response.AddHeader "Content-Length", objFile.Size
Response.ContentType = strContentType ' "application/octet-stream"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
'-- set as binary
objStream.Type = 1
Response.CharSet = "UTF-8"
'-- load into the stream the file
objStream.LoadFromFile(strAbsFile)
'-- send the stream in the response
Response.BinaryWrite(objStream.Read)
objStream.Close
response.flush
Set objStream = Nothing
Set objFile = Nothing
Else 'objFSO.FileExists(strAbsFile)
Response.Clear
Response.Write("No such file exists.")
End If
That bit of code should force download and in your case, create the attachment. I am short of time right now and will come back to this later for you to try and recreate with your vcard example.
I think the key items are
Response.AddHeader "Content-Disposition", "attachment; filename=" & filename
Response.ContentType = strContentType ' "application/octet-stream"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
'-- set as binary
objStream.Type = 1
Response.CharSet = "UTF-8"
'-- load into the stream the file
objStream.LoadFromFile(file_location) ' where filelocation is the external call to vcard.asp?event=123
'-- send the stream in the response
Response.BinaryWrite(objStream.Read)
objStream.Close
response.flush
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
worked perfectly. Truly appreciate your insight and helpful hints.
Thanks for the side help with sending via gmail too. I didn't know about that.
Thanks for the side help with sending via gmail too. I didn't know about that.
That is good news, I'm glad it worked out!
vcard.asp
Open in new window
Now when you add your attachment, use https://example.com/vcard.asp?event=123
Open in new window
[/code]
The main idea is you are creating the attachment in another asp file that streams as a file. a vcard is just a text file. See if that works and let me know if you have any issues. I will try and look through my archives for this because I have done this before. It just has been a long time.