473,416 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 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 6812
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 pear.php.net Works great so far but..... ...
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 c:\hosting\webhost4life\member\soibry\webmail\webmail.php on line 58 ...
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 spits out a bunch of junk . I know this should...
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 the DataSet as XML file, 2.zip the XML file. 3....
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 be an insertion which is replacing the plain text...
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 RSA signature). What is the best way to convert...
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 file in plain text but if I encode and send it, I...
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 how can i get from database and then add to my mail....
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 able to send data without attachment but with the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.