473,583 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CDO.sys to send mail with base64 encoding ASP help

2 New Member
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 6829
maxxxxel
2 New Member
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
2279
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..... ....Sometimes (depending on the mail server that handles the mailing) all quotation marks in an HTML body of a multipart message become escaped.
5
2584
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 The source code is: <?php #variable passed are $to,$from,$re,$comments,$att1
3
2129
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 be pretty simple, but I have been pulling my hair out for hours with this. :/ Can someone smart pleaseeee help me tweak this code to work? <?php...
4
18538
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. send the zip file to WebService. 4. Unzip the zip file to XML. 5. Load XML file into DataSet. 6.Bulk copy the XML file to DataBase.
0
2131
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 part of the email with something else. Looking at the server sent email source, the hacked emails have the following: This is a multi-part message...
5
5846
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 the original byte () value to the xml and viceversa? I've tried a lof of way, as encoding.utf8, encoding.unicode, bitconverter, etc, but the only...
1
1589
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 get some stupid data. I make use of base64 to encode the file. Here is the tags with data that I send to mail server. MIME-Version: 1.0 From:...
1
2410
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. <?php function send_mail($emailaddress, $fromaddress, $emailsubject, $body, $ccaddress, $attachments=false) { $eol="\r\n"; ...
1
3199
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 code for attachment, I am not able to send anything. I get blank email. Can you please help me on this? Here is the html form:
0
7896
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8184
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8328
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7936
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8195
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5375
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3820
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1434
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1158
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.