Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CDO corrupting attachments

Status
Not open for further replies.

travisbrown

Technical User
Dec 31, 2001
1,016
Okay. Biggish problem for an app that's in production.

I'm just trying to fix. Another developer wrote it, so forgive the messy code. I've reformatted it a bit for this post.

Here's the situation.

Files are uploaded to db as BLOBs, then attached to emails sent through CDO. The files upload fine, are streamed back to disk for download and attachment fine, but sometimes get corrupted when sent through CDO. has anyone seen this before? I've only noticed it on PDFs > 2mb so far.

I've followed the process path through and checked the files 1.before upload 2.after streamed back do disk for attachment through CDO 3. after FSO-moved to another directory. All are fine, but when I get the email, the file is corrupted. It's happening somewhere between send and receive. I've tested on several different W2k3 servers, all with the same result.
Here is the binary stream code and the cdo code. I don't see anything glaringly wrong, but maybe new eyes...C

Code:
<%
if Ubound(arrSelFiles) > 0 then
	for iLoop = 0 to Ubound(arrSelFiles) - 1
		strSql =  "SELECT [file],[extension] FROM tblDistributionCorrespondence WHERE fid = " & strMaxId & " AND id = " & arrSelFiles(iLoop)
		rsFileContent.open strSql,objConn,1
		 response.write strsql
		 If Not rsFileContent.EOF  and strAttach <> "" Then
			while not rsFileContent.EOF
				strFileName= rsFileContent("extension")
				sqlSendFile = "INSERT INTO tblSendFiles(sendID,fileAttached,fid) VALUES("
				sqlSendFile = sqlSendFile &  strMaxEmailSendID &",'" &strFileName & "'," & arrSelFiles(iLoop) & ")"
				objConn.Execute(sqlSendFile)
				strStream.Type = 1
			  	strStream.Open
				strStream.Write rsFileContent("file").Value
			    strStream.SaveToFile strFolder&"\"&strFileName,2
				strAttachments = strFolder&"\"&strFileName
				obj_Mail.AddAttachment strAttachments
				iCount = iCount + 1
				strStream.close
				rsFileContent.moveNext
			wend
		End If
		rsFileContent.Close
		'Set rsFileContent = Nothing

	next
End if

obj_Mail.From = "emailtest@email.com"
obj_Mail.subject = strHeader
obj_Mail.HTMLBody = strFooter

sqlApplication = "SELECT DISTINCT tblContact.id,email FROM "
sqlApplication = sqlApplication & " (((tblDistribution LEFT JOIN tblDistributionContact "
sqlApplication = sqlApplication & " ON tblDistribution.[id] = tblDistributionContact.fid)"
sqlApplication = sqlApplication & " INNER JOIN tblContact ON tblContact.[id] = tblDistributionContact.contact_id)"
sqlApplication = sqlApplication & " INNER JOIN tblContactEmail ON tblContact.[id] = tblContactEmail.fid)"
sqlApplication = sqlApplication & " INNER JOIN tblContactDeliveryMode ON tblContactDeliveryMode.fid = tblContact.[id]"
sqlApplication = sqlApplication & " WHERE tblDistribution.[id] = "& strMaxId & " AND authUser='"& request.querystring("vuser")& "'"
sqlApplication = sqlApplication & " AND tblContactDeliveryMode.mode = 1"

rstApplication.open sqlApplication,objConn,1



if not rstApplication.EOF then
	recips = "emailtest@email.ca"
	while not rstApplication.EOF
		strName = rstApplication("id")
		strToEmail = rstApplication("Email")
		sqlSendRecipients = "INSERT INTO tblEmailRecipients(sendID,RecipientEmail,Recipient) VALUES("
		sqlSendRecipients = sqlSendRecipients &  strMaxEmailSendID & ",'" & strToEmail & "','" & strName & "')"
		'response.write sqlSendRecipients
		recips = recips & ";" & rstApplication("Email")
		objConn.Execute(sqlSendRecipients)
		rstApplication.moveNext
	wend
		obj_Mail.To = recips
		obj_Mail.Send
end if
%>
 
Narrowed it down to the dot stuffing glitch in CDO

If I attach a textfile with

1.
2.
.3
.4
5
6

the received file looks like this:

1.
2.
3
4
5
6

SMTP strips out leading periods. This is what is corrupting the files. I'd read that changing the encoding between UUEncode and Base64 would fix, but I get the same with both.

obj_Mail.AddAttachment strAttachments,0
 
So if I change the attaced file's contents to
..1
..2
..3
4.
5.
6

i get

.1
.2
.3
4.
5.
6
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top