472,328 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

CDO.sys to send mail with base64 encoding ASP help

Hi

Can anyone help me with some asp code , I changed the code to use CDO.message instead of the old cdont.sys to send mail from a ASP webpage which works fine.

Our problem is that when we send mail externally to a internet email site like Gmail the PDF is sent but is corrupted because CDOSYS ends up using binary encoding
rather than Base64 encoding when creating the attachment. More information here: Anthonys Code

My knowledge of ASP is basic. The second bit of code is at the bottom is written by Anthony so i am trying to change my code to support base64 with the help of his code but at th moment i am lost

Thanks for any imput :-)

Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3. if Session("LoggedIn") = False Then
  4. Response.Redirect("autoexit.htm")
  5. end if
  6. Response.Buffer = False
  7. Server.ScriptTimeout = 310
  8.  
  9. Dim Q, iAtt, bErr, strErrNum, strErrDesc, strFilepath, PCL2PDF, ObjReference
  10. Dim strFrom, strTo, strCC, strSubject, strBody, strAttachments, strFromString, strSubjectString
  11. Dim strCompany, strDocumentname, strInvoicenumber, strVisibleFileName, strExtension 'for building the visible attachment name
  12. Dim strUser, strPassword, strServer, strDatabase 'connection-variables to the database
  13. Dim strShortAttName 'e.g.: 154209.tif
  14. Dim strAttFileName ' e.g.: KundFaktura29875199F3769788749425000.gz
  15. Dim strAttFile 'e.g.: DFC6C9CECAC8CCCACACC154209.tif
  16. Dim dosendmail
  17.  
  18. Q = Chr(34)
  19. iAtt=0
  20. bErr = False
  21. strErrNum = ""
  22. strErrDesc = ""
  23. strFilepath = Application("filepath")+Session("sid")+"\"
  24. PCL2PDF = Request.Cookies("PCL2PDF")
  25. strUser = Session("u")
  26. strPassword = Session("p")
  27. strServer = Request.Cookies("RePrintWebClient")("s")
  28. strDatabase = Request.Cookies("RePrintWebClient")("d")
  29.  
  30. Function AttachmentName(ObjId, FileType)
  31. Dim strFilename 'the real filename in the temp-directory, e.g.: .PDF or .MIME
  32. Dim splitFile 'array
  33. If UCase(FileType)="PCL" Then
  34.  
  35. If PCL2PDF = "No" Then
  36. strFilename = ObjReference.GetAttachmentName(strUser, strPassword, strServer, strDatabase, strFilepath, ObjId, FileType)
  37. Else
  38. strFilename = ObjReference.GetAttachmentNamePDF(strUser, strPassword, strServer, strDatabase, strFilepath, ObjId, FileType)
  39. End If
  40. Else
  41. strFilename = ObjReference.GetAttachmentName(strUser, strPassword, strServer, strDatabase, strFilepath, ObjId, FileType)
  42. End If
  43. If Left(strFilename, 5)="ERROR" Then
  44. strFilename = ""
  45. End if
  46.  
  47. If ucase(right(strFilename,4))="MIME" Then
  48. splitFile = split(ObjReference.GetAttachmentFile( strFilepath+strFilename ),"#")
  49. strShortAttName = splitFile(0)
  50. strAttFileName = splitFile(1)
  51. strAttFile = splitFile(2)
  52. 'strTo = splitFile(3)
  53. 'strCC = splitFile(4)
  54. 'strFromString = splitFile(5)
  55. 'strSubjectString = splitFile(6)
  56. Else
  57. strShortAttName = strFilename
  58. End If
  59. strExtension = right(strShortAttName,len(strShortAttName)-InStrRev(strShortAttName,".")+1)
  60. If ucase(right(strFilename,4))="MIME" Then
  61. strVisibleFileName = left(strFilename,len(strFilename)-5) & strExtension
  62. AttachmentName = strFilepath & ObjReference.GetConfiguration(strServer,strDatabas  e,strUser,strPassword,"mailcompany") & " " & Request.Form("objType") & " " & ObjReference.GetAtt(strUser, strPassword, strServer, strDatabase, strFilepath, ObjId, strAttFileName, strAttFile)
  63. Else
  64. strVisibleFileName = strFilename
  65. AttachmentName = strFilepath & strFilename
  66. End If
  67. End Function
  68.  
  69. Function Sendmail()
  70. Dim Mail, strmailitems, splitmailitems, i, splitmailitem, splitobjid, splitft
  71. strmailitems = Request.Form("mailitems")
  72. splitmailitems = split(strmailitems,";")
  73. Set Mail = CreateObject("CDO.Message")
  74.  
  75.  
  76.  
  77.  
  78. If err.number = 0 then
  79. for i=0 to ubound(splitmailitems) step 1
  80. splitmailitem = splitmailitems(i)
  81. splitft = mid(splitmailitem,instr(splitmailitem,"#")+1)
  82. splitobjid = mid(splitmailitem,1,len(splitmailitem)-len(splitft)-1)
  83. If splitmailitem <> "" Then
  84. Mail.AddAttachment AttachmentName(splitobjid,splitft),strVisibleFileN  ame
  85. iAtt = iAtt + 1
  86. End If
  87. next
  88. Mail.From = strFrom
  89. Mail.To = strTo
  90. Mail.CC = strCC
  91. Mail.Subject = strSubject
  92. ' Mail.BodyFormat = 1
  93. ' Mail.MailFormat = 1
  94. ' Mail.Body= strBody
  95. Mail.Configuration.Fields.Item _
  96. ("h***p://schemas.microsoft.com/cdo/configuration/sendusing")=2
  97.  
  98. 'Name or IP of remote SMTP server
  99. Mail.Configuration.Fields.Item _
  100. ("h***p://schemas.microsoft.com/cdo/configuration/smtpserver") _
  101. ="**********"
  102. 'Server port
  103. Mail.Configuration.Fields.Item _
  104. ("h***p://schemas.microsoft.com/cdo/configuration/smtpserverport") _
  105. =25
  106.  
  107. Mail.Configuration.Fields.Update
  108. Mail.Send
  109. Set Mail = Nothing
  110. Else
  111. bErr = True
  112. strErrDesc = err.description
  113. strErrNum = err.number
  114. End if
  115. Set ObjReference = Nothing
  116. End Function
  117.  
  118. Function GetFormData()
  119. Dim strmailitems, splitmailitems, i, splitmailitem, splitobjid, splitft, strtest, strAhref
  120. strmailitems = Request.Form("mailitems")
  121. strAhref = ""
  122. splitmailitems = split(strmailitems,";")
  123. If err.number = 0 then
  124. for i=0 to ubound(splitmailitems) step 1
  125. splitmailitem = splitmailitems(i)
  126. splitft = mid(splitmailitem,instr(splitmailitem,"#")+1)
  127. splitobjid = mid(splitmailitem,1,len(splitmailitem)-len(splitft)-1)
  128. If splitmailitem <> "" Then
  129. strtest = AttachmentName(splitobjid,splitft)
  130. If UCase(splitft)="MIME" Then
  131. strAhref = strAhref & "<a href=" & Q & "Show Attachment" & Q & " OnClick=" & Q & "ShowAtt('" & splitobjid & "','" & strAttFileName & "','" & strAttFile & "');return false" & Q & "><img border=" & Q & "0" & Q & " src=" & Q & "images/att.gif" & Q & " align=" & Q & "texttop" & Q & ">" & strVisibleFileName & "</a><br>"
  132. Else
  133. strAhref = strAhref & "<a href=" & Q & "Show Attachment" & Q & " OnClick=" & Q & "Show('" & splitobjid & "','" & splitft & "');return false" & Q & "><img border=" & Q & "0" & Q & " src=" & Q & "images/att.gif" & Q & " align=" & Q & "texttop" & Q & ">" & strVisibleFileName & "</a><br>"
  134. End If
  135. strAttachments = strAttachments & strVisibleFileName
  136. iAtt = iAtt + 1
  137. End If
  138. next
  139. Else
  140. bErr = True
  141. strErrDesc = err.description
  142. strErrNum = err.number
  143. End if
  144. Response.Write "<table width=" & Q & "70%" & Q & " bgcolor=" & Q & "#FFFFFF" & Q & " style=" & Q & "border-style:groove;border-width:medium" & Q & ">"
  145. Response.Write "<tr>"
  146. Response.Write "<td width=" & Q & "110" & Q & " valign=" & Q & "top" & Q & "><b>From:</b></td>"
  147. Response.Write "<td title=" & Q & "From" & Q & " valign=" & Q & "top" & Q & "><INPUT type=" & Q & "text" & Q & " name=" & Q & "fldFrom" & Q & " id=" & Q & "fldFrom" & Q & " value=" & Q & strFrom & Q & " style=" & Q & "width:100%" & Q & "></td>"
  148. Response.Write "</tr>"
  149. Response.Write "<tr>"
  150. Response.Write "<td width=" & Q & "110" & Q & " valign=" & Q & "top" & Q & "><b>To:</b></td>"
  151. Response.Write "<td title=" & Q & "To" & Q & " valign=" & Q & "top" & Q & "><INPUT type=" & Q & "text" & Q & " name=" & Q & "fldTo" & Q & " id=" & Q & "fldTo" & Q & " value=" & Q & strTo & Q & " style=" & Q & "width:100%" & Q & "></td>"
  152. Response.Write "</tr>"
  153. Response.Write "<tr>"
  154. Response.Write "<td width=" & Q & "110" & Q & " valign=" & Q & "top" & Q & "><b>Cc:</b></td>"
  155. Response.Write "<td title=" & Q & "Cc" & Q & " valign=" & Q & "top" & Q & "><INPUT type=" & Q & "text" & Q & " name=" & Q & "fldCC" & Q & " id=" & Q & "fldCC" & Q & " value=" & Q & strCC & Q & " style=" & Q & "width:100%" & Q & "></td>"
  156. Response.Write "</tr>"
  157. Response.Write "<tr>"
  158. Response.Write "<td width=" & Q & "110" & Q & " valign=" & Q & "top" & Q & "><b>Subject:</b></td>"
  159. Response.Write "<td title=" & Q & "Subject" & Q & " valign=" & Q & "top" & Q & "><INPUT type=" & Q & "text" & Q & " name=" & Q & "fldSubject" & Q & " id=" & Q & "fldSubject" & Q & " value=" & Q & strSubject & Q & " style=" & Q & "width:100%" & Q & "></td>"
  160. Response.Write "</tr>"
  161. Response.Write "<tr>"
  162. Response.Write "<td width=" & Q & "110" & Q & " valign=" & Q & "top" & Q & "><b>Body:</b></td>"
  163. Response.Write "<td title=" & Q & "Body" & Q & " valign=" & Q & "top" & Q & "><textarea name=" & Q & "fldBody" & Q & " id=" & Q & "fldBody" & Q & " wrap=" & Q & "soft" & Q & " style=" & Q & "width:100%;font-family:Verdana;font-size:8pt" & Q & ">" & strBody & "</textarea></td>"
  164. Response.Write "</tr>"
  165. Response.Write "<tr>"
  166. Response.Write "<td width=" & Q & "110" & Q & " valign=" & Q & "top" & Q & "><b>Attachments:</b></td>"
  167. Response.Write "<td title=" & Q & "View attachment" & Q & " valign=" & Q & "top" & Q & ">"
  168. Response.Write strAhref
  169. Response.Write "</td>"
  170. Response.Write "</tr>"
  171. Response.Write "</table>"
  172. Set ObjReference = Nothing
  173. End Function
  174.  
  175.  
  176. %>
Anthonys Code to send base64 attachments

Expand|Select|Wrap|Line Numbers
  1. Function AddAttachment(Message, Source, FileName, MimeType)
  2.  
  3. Dim oPart ' As IBodyPart
  4. Dim oStreamIn ' As ADODB.Stream
  5. Dim oStreamOut ' As ADODB.Stream
  6.  
  7. Set oPart = Message.Attachments.Add
  8.  
  9. oPart.ContentMediaType = MimeType & "; Name = """ & FileName & """"
  10. oPart.ContentTransferEncoding = "base64"
  11. oPart.Fields("urn:schemas:mailheader:content-disposition").Value =
  12. "attachment; FileName = """ & FileName & """"
  13. oPart.Fields.Update
  14.  
  15. Set oStreamIn = Server.CreateObject("ADODB.Stream")
  16.  
  17. oStreamIn.Open
  18. oStreamIn.Type = adTypeBinary
  19. oStreamIn.LoadFromFile Source
  20.  
  21. Set oStreamOut = oPart.GetDecodedContentStream
  22.  
  23. oStreamIn.CopyTo oStreamOut
  24.  
  25. oStreamOut.Flush
  26.  
  27. oStreamIn.Close
  28.  
  29. Set AddAttachment = oPart
  30.  
  31. End Function
  32.  
  33.  
Dec 20 '07 #1
1 6627
Fixed it :)

I cant believe it was so simple :)

I just needed to add:

Expand|Select|Wrap|Line Numbers
  1. Mail.HTMLBody = ("message")
This causes the encoding of the mail to change
Dec 20 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Jerry | last post by:
Hi People ! I have an Urgent Problem and greatly appreciate your help: My script sends multipart emails using the MAIL_MIME package from...
5
by: nick | last post by:
The code always returen the following error at fclose(fp). Fatal error: Maximum execution time of 30 seconds exceeded in...
3
by: marsandys | last post by:
Hello, I have this code below, which I am trying to have it send HTML formatted mail with embedded images. I can get this to send the mail, but it...
4
by: ad | last post by:
I want to send a DataSet to WebService, but the DataSet if too huge(there about 50000 records, and 50 fields every record). My solution is 1.save...
0
by: nauticalmac | last post by:
I'm using CDO to send mail to the site owner from ASP pages with forms. Recently one of my forms is occasionally sending email with what seems to...
5
by: Trapulo | last post by:
Hello, I need to send to a webservice a parameter that is a string containing an XML doc. In this xml, a node value came from a byte array (it's an...
1
by: vermarajeev | last post by:
Hi guys, I have a plain text file. I want to encrypt and send this file via mail. I use SMTP to send the file over network. I'm able to send the...
1
by: Chitu03 | last post by:
Hi I am already send a mail using Php with some attachement into it. My Problem is the attachement file is in my Database(mysql). I don't know...
1
by: deepaks85 | last post by:
Dear All, I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.