Copy link to clipboard
Copied
I want to send a mail which has a PDF attachment and an embedded image. When I send them both with cfmailparam (with correct disposition) they arrive in the email as attachments in the body...you don't get the little email paperclip attachment icon.
When I tried using mimeattach for the PDF it did work!...but the image denoted with cfmailparam also came through like that. So I looked the email headers of both and the good one was Content-Type: multipart/mixed; while the bad one was "multipart/related".
So how can I make cfmailparam send it as multipart/mixed? (if that's even the right question...maybe I should stick with mimeattach and do something else?)
Thanks Folks' - Randy
Copy link to clipboard
Copied
Hi,
Cloud you please try the following,
<cfmail ..... type="text/html">
<cfmailparam file="./attachments/my.pdf" disposition="attachment">
<cfmailparam file="./attachments/thumbnails/test.jpg"
disposition="inline" contentID="image1">
<img src="cid:image1"><br>
</cfmail>
------
Please attach the code set that you have tried
Copy link to clipboard
Copied
Thank you for the quick reply... is it possible this is something to do with the host or CF admin config?
I tried your code (it seemed to be close to what I had) exactly as here...
====================================
<cfmail to="...." from="...." subject="mime test3">
<cfmailparam file="#ExpandPath('./....the path....')#" disposition="attachment">
<cfmailparam file="#ExpandPath('./...the path...')#" disposition="inline" contentID="image1">
<img src="cid:image1"><br>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</cfmail>
====================================
I also tried multipart,...and also with type="text/html" in the CFMail header.... all of them come through with the file in the body and with Content-Type:multipart/related.
Now, on your email to me, from catchme_dileep, there was the paperclip showing and I again confirmed the Content-Type: multipart/mixed;
So what determines that Content-Type? When I send from my host it's multipart/related, from you it's multipart/mixed. (file attached showing your email and mine...you get the paperclip....important because I'm told Outlook doesn't seem the attachments in the body).
(What's mime is yours?)
Copy link to clipboard
Copied
After further, and further, with the very great help from my webhost, (YoHost , Brett, always remarkably quick to reply and helpful. 4 stars), it seems that when a contentID is specified the email comes through with a multipart/related (which causes the attached file to be accessible only after opening the email...Eudora shows the paper clip, Yahoo doesn't, but regardless the file doesn't end up on the desktop as with multipart/mixed.)
I even tried specifying explicitly as such (but no dice)...
<cfmailpart type="multipart/mixed">
<cfmailparam file="#ExpandPath('hello.pdf')#" disposition="attachment">
<cfmailparam file="#ExpandPath('folder.gif')#" disposition="inline" contentID="image1">
<img src="cid:image1"><br>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</cfmailpart>
So that's that for now I think ...enough time invested for all and I'll want to hear sometime perhaps from the folks at the source.
Copy link to clipboard
Copied
How do I find out if there's a known bug with CFmail not sending as multipart/mixed even when it's explicitly specified (it presently sends as multipart/related).
I need to know because:
1) I want to know if it will be fixed
2) If it's a bug I can charge my time to find it to my client (because the four hours I've spent to isolate it would'nt be my fault.)
Copy link to clipboard
Copied
I'm running into the same issue.
I am sending emails with attachments but they are sent as 'multipart/related' rather than 'multipart/mixed'. Outlook assumes that the attachments are inline when the type is 'related' so they don't show up at all and there is no indication that an attachment exists. How can I force a content type of multipart/mixed?
<cfmail to="#vSentTo#" from="#application.replyToEmail#" replyto="#application.replyToEmail#" cc="#vSentCC#" bcc="#vSentBCC#" mailerid="Lotus Notes Release 8.5.2 August 10, 2010" subject="#form.subjectText#" type="html">
<cfmailparam file="#newFilename#" disposition="attachment" content="#qFile.fileContent#" type="#qFile.mimeType#" contentid="#createUUID()#">
<cfmailpart type="text/plain" charset="utf-8">#form.emailContent#</cfmailpart>
<cfmailpart type="text/html" charset="utf-8">#replaceNoCase(form.emailContent,chr(13),'<br />','All')#</cfmailpart>
</cfmail>
Copy link to clipboard
Copied
The tags CFMAIL, CFMAILPART, and CFMAILPARAM all support an optional "type" attribute that can be used to specify a MIME type. I would try specifying the mime type that you'd like to use.
Copy link to clipboard
Copied
I've tried changing the type to 'multipart/mixed' in each of the tags. The email still gets sent as multipart/related.
This is what I get:
Content-Type: multipart/related;
boundary="----=_Part_12_1564404103.1299862102449"
------=_Part_12_1564404103.1299862102449
Content-Type: multipart/alternative;
boundary="----=_Part_11_2023764527.1299862102449"
This is what I need:
Content-Type: multipart/mixed; boundary="=_mixed 005D0AF685257850_="
--=_mixed 005D0AF685257850_=
Content-Type: multipart/alternative; boundary="=_alternative 005D0AF685257850_="
Copy link to clipboard
Copied
Can you post the changes you made to your code?
Copy link to clipboard
Copied
It looks like CF is overwriting or ignoring the MIME type specified in code when CFMAILPARAM is used. If CFMAILPARAM tags are omitted and type="multipart/mixed" is specified in CFMAIL an exception is thrown.
I suspect that the mime value for the Content-Type header is being overwritten when attachments are added because CF needs to add boundary information to the email message to separate the body from the attachments. I would submit this as a bug to Adobe given that the expected behavior would be the to use the MIME type specified in code.
Copy link to clipboard
Copied
<cfmail to="#vSentTo#" from="#application.replyToEmail#" replyto="#application.replyToEmail#" cc="#vSentCC#" bcc="#vSentBCC#" subject="#form.subjectText#" type="multipart/mixed">
<cfmailparam file="#newFilename#" disposition="attachment" content="#qFile.fileContent#" type="#qFile.mimeType#" contentid="#createUUID()#">
<cfmailpart type="text/plain" charset="utf-8">#form.emailContent#</cfmailpart>
<cfmailpart type="text/html" charset="utf-8">#replaceNoCase(form.emailContent,chr(13),'<br />','All')#</cfmailpart>
</cfmail>
Above is an example where I changed the type in <cfmail>. I also tried changing the type in <cfmailparam> but that resulted in a malformed attachment. Changing the type in <cfmailpart> didn't make any difference. I also tried adding a separate tag:
<cfparam name="Content-Type" value="multipart/mixed>
but that didn't make a difference either.
Copy link to clipboard
Copied
Has somebody found a solution for this problem?
I have tried this:
"What you really need for your problem is both. You need an outer MIME message of type multipart/mixed which contains the attachment and an inner part. The inner part should be of type multipart/related and should contain the text message and the inline image. I am not sure whether it is possible to construct a message like that in CF, you would have to nest cfmailpart tags inside eachother.. Jochem"
But that doesn't seems to work either.
Copy link to clipboard
Copied
I never found a solution using cfmail. I had to resort to java instead.
I have all of my file information (including content) in a query called qFiles and loop through that in the code below.
<cfscript>
// config will stay this way
emailServer = serverAddressHere;
emailServerAccount = "";
emailServerPwd = "";
// set email variables
vSentFrom = sentFromEmailHere;
vSubjectText = subjectHere;
recipientsTo = listToArray( SentToListHere );
recipientsCC = listToArray( CCListHere );
recipientsBCC = listToArray( BCCListHere );
// set javamail properties
props = createObject("java", "java.util.Properties").init();
props.put("javax.mail.smtp.host", emailServer);
// get static recipient types
recipientType = createObject("java", "javax.mail.Message$RecipientType");
// create the session for the smtp server
mailSession = createObject("java", "javax.mail.Session").getInstance(props);
// create a new MIME message
mimeMsg = createObject("java", "javax.mail.internet.MimeMessage").init(mailSession);
// create the to and from e-mail addresses
addrFrom = createObject("java", "javax.mail.internet.InternetAddress").init(vSentFrom);
for (cfIdx = 1; cfIdx LTE arrayLen( recipientsTo ); cfIdx++)
{
addrTo[cfIdx] = createObject("Java", "javax.mail.internet.InternetAddress").init( recipientsTo[cfIdx] );
// add a recipient
mimeMsg.addRecipient(recipientType.TO, addrTo[cfIdx]);
}
if(ArrayLen(recipientsCC)){
for (cfIdx = 1; cfIdx LTE arrayLen( recipientsCC ); cfIdx++)
{
addrCC[cfIdx] = createObject("Java", "javax.mail.internet.InternetAddress").init( recipientsCC[cfIdx] );
// add a recipient
mimeMsg.addRecipient(recipientType.CC, addrCC[cfIdx]);
}
}
if(ArrayLen(recipientsBCC)){
for (cfIdx = 1; cfIdx LTE arrayLen( recipientsBCC ); cfIdx++)
{
addrBCC[cfIdx] = createObject("Java", "javax.mail.internet.InternetAddress").init( recipientsBCC[cfIdx] );
// add a recipient
mimeMsg.addRecipient(recipientType.BCC, addrBCC[cfIdx]);
}
}
// build message
// set who the message is from
mimeMsg.setFrom(addrFrom);
// set the subject of the message
mimeMsg.setSubject(vSubjectText);
// create multipart message: only needed if you're including both plain/text and html
// or using attachments
multipart = createObject("java", "javax.mail.internet.MimeMultipart").init();
// specifies that the message contains both inline text and html, this is so that
// images given a cid will show up when rendered by the e-mail client
multipart.setSubType("mixed");
// create html text multipart
oHtml = createObject("java", "javax.mail.internet.MimeBodyPart").init();
// add the html content (the setText() method shortcut/only works for "plain/text")
oHtml.setContent( emailContentHTML, "text/html");
// add the body part to the message
multipart.addBodyPart(oHtml);
// loop over files to attach to the email
for ( intRow = 1 ; intRow LTE qFiles.RecordCount ; intRow = (intRow + 1))
{
// set file info to vars
fileContent = qFiles["fileContent"][intRow];
fileMimeType = qFiles["mimeType"][intRow];
fileName = rereplace( qFiles["filename"][intRow] , '(?!\.[^.]*$)\W' , '' , 'all' );
if(len(fileName) > 50)
{fileName = mid(fileName,1,44) & right(fileName,find('.',reverse(fileName)));}
// attach an inline binary object
att = createObject("java", "javax.mail.internet.MimeBodyPart").init();
// create an octet stream out of the binary file
os = createObject("java", "org.apache.axis.attachments.OctetStream").init(fileContent);
// we now convert the octet stream into the required data source. using an octet stream
// allows us pass in any binary data as a file attachment
osds = createObject("java", "org.apache.axis.attachments.OctetStreamDataSource").init("", os);
// initialize the data handler using the data source
dh = createObject("java", "javax.activation.DataHandler").init(osds);
// pass in the binary object to the message--javamail will handle the encoding
// based on the headers
att.setDataHandler(dh);
// define this binary object as a PDF
att.setHeader("Content-Type", fileMimeType);
// make sure the binary data gets converted to base64 for delivery
att.setHeader("Content-Transfer-Encoding", "base64");
// specify the binary object as an attachment
att.setHeader("Content-Disposition", "attachment");
// define the name of the file--this is what the filename will be in the e-mail client
att.setFileName(fileName);
// add the body part to the message
multipart.addBodyPart(att);
}
//end loop through qFiles
// place all the multi-part sections into the body of the message
mimeMsg.setContent(multipart);
// in this section we'll build the message into a string. you could dump
// the string to a file in most SMTP server's queue file for delivery
// this is exactly what would be pass to the SMTP server
// create a bytearray for output
outStream = createObject("java", "java.io.ByteArrayOutputStream");
// create a budder for the output stream
outStream.write(repeatString(" ", 1024).getBytes());
// save the contents of the message to the output stream
mimeMsg.writeTo(outStream);
// save the contents of the message to the sMailMsg variable
sMailMsg = outStream.toString();
// reset the output stream (for stability)
outStream.reset();
// close the output stream
outStream.close();
// create a transport to actually send the message via SMTP
transport = mailSession.getTransport("smtp");
// connect to the SMTP server using the parameters supplied; use
// a blank username and password if authentication is not needed
transport.connect(emailServer, emailServerAccount, emailServerPwd);
// send the message to all recipients
transport.sendMessage(mimeMsg, mimeMsg.getAllRecipients());
// close the transport
transport.close();
</cfscript>
Copy link to clipboard
Copied
I just wanted to bump this back to the top and see if anyone else had figured out a solution for this with cfmail? We have clients using iPhone/iPads, etc that are experiencing issues where they do not see attachments. In addition, clients like Thunderbird don't include the attachments when forwarding messages. We'd like to get this resolved.