Changing filename of attachment in CFMail - email

I'm trying to use ColdFusion to send out emails containing attachments stored on our server.
To manage these attachments we call them 1.jpg, 2.doc ... n.ext where n is a key in a database where we hold other information about the file such as its original filename.
I can use the code:
<cfmailparam file="c:\path\1.doc">
to specify the file, but it is then attached to the email as 1.doc. Is there anyway I can override this and specify my own filename separately from the file?

You can try adding:
<cfmailparam
file="#actual_file_name#"
disposition="attachment; filename=""#changed_file_name#""">
The multiple quotes are deliberate... I they allow spaces in the file name.

Ryan's suggestion is probably the easiest solution. If you're on CF 8.01 you can make use of cfmailparam's new remove attribute. After you've renamed your attachments with cffile and passed them to cfmailparam, Coldfusion will delete them from disk for you once they have been processed by the mail spool:
<cfmailparam file="#File_path#" remove="true" />
(Before version 8.01, you had to make sure that your app didn't delete the temp files before Coldfusion's mail spool was finished with them.)
Alternatively you could call Coldfusion's underlying Java and construct your email message with attachments from memory only, with whatever names you fancy. Check out Dan Switzer's blog for an example on CF 7.02.

ColdFusion 2016 added this new attribute called filename to override the filename specified in the file attribute. A sample example is below
<cfmail from="john#sample.com" subject="filename test" to="joanna#sample.org" username="john#sample.com" password="password" server="localhost" spoolenable="false">
<cfmailparam file="c:\Book2.xlsx" filename="Offers.xlsx">
Check out the new offers sheet
</cfmail>
Now when the mail is sent to the user he/she will see this as Offers.xslx instead of Book2.xslx. More info at https://tracker.adobe.com/#/view/CF-4019518

currently the only way to do this would be to use cffile and make a copy of the file in a temporary directory, rename it and then attach that. Then you would just want to delete the file once you are finished. I don't think there is a way to attach a file but call it something different when attaching to an email.

If you are running 8.0.1 (do cfdump var="#server#" to find out) then this might make your life a little easier:
The cfmail and cfmailparam tags now have a remove attribute that tells ColdFusion to remove any attachments after successful mail delivery.
The cfmailparam tag now has a content attribute that lets you send the contents of a ColdFusion variable as an attachment. To do so, specify the variable in # signs as the content attribute value, as in the following example:
The file attribute specifies the file name to include in the mail header, not a file on the ColdFusion system
From:
http://www.adobe.com/support/documentation/en/coldfusion/801/cf801releasenotes.pdf

Since CF8 you can use file and content as per : http://www.bennadel.com/blog/1220-coldfusion-cfmailparam-s-new-content-attribute-is-awesome.htm
<cfmailparam
file="someNiceName.doc"
content="#fileRead( yourNastyFileName.doc )#"
/>

Related

Mailcow sieve script that removes attachments and adds a message to the body

I'm trying to find out how to remove non-whitelisted attachments (by mime type) (f.e. zip, exe, ...)
and append a message about the removed attachments.
I found this: https://superuser.com/a/1502589
And it worked to add a message to the subject.
But I cannot find out how to add a message to the body.
My plan was to use a regex on the attachment mime types and allow f.e.
text/* and application/json etc.
But I cannot find a single example how to change the body.
I'm using mailcow and sieve script (which I'm both new to).
Or is there a better way to "sanitize" emails before the get put into the inbox?
EDIT (2023-02-07) : I found this today:
Extension foreverypart.
Sieve Email Filtering: MIME Part Tests, Iteration, Extraction, Replacement, and Enclosure
https://www.rfc-editor.org/rfc/rfc5703.html \
The "replace" command is defined to allow a MIME part to be replaced
with the text supplied in the command.
Exactly what I try to do.
Now I need to find out how to install the extension and try it out.

Need to send email with Attachment from Matillion Tool

Need to send email with Attachment from Matillion Tool
I have checked SNS Message,Send Email component from Matillion but it does not have attachment option.
I have Error log table into Amazon Redshift and I want to retrieve those records and load into one file on daily basis( can be put on S3/SFTP ) this file I want to add as attachment to email and send it to vendor for further analysis.
Found this : https://metlcommunity.matillion.com/s/question/0D54G00007lwu2DSAQ/send-email-with-attachment-of-errors but couldn't help.
https://metlcommunity.matillion.com/s/question/0D54G00007lwu2DSAQ/send-email-with-attachment-of-errors
Based on this message on the Matillion site, it looks like currently there is no built-in component for sending an email with an attachment, but it is on the product roadmap to add one.
There are some hosted downloadable jobs that can send emails - e.g. this and this. It is not clear if they can handle attachments, but at least the Python code inside them might be helpful..
You can do this with the python component in Matillion.
If the target file is on S3, you can use the python boto3 package to download the file to the matillion server.
Then you can use the smtp package in python to create the email and attach the file.
this is example code to attach a file where the filename is in the variable filename_out
filename_out = "/tmp/" + "myfile.logs"
part = MIMEBase('application', "octet-stream")
part.set_payload(open(filename_out, "rb").read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename=' + filename_out)
message.attach(part)

change recipient / attach a file to a sent email in outlook

I've been trying to test something out, basically looking to do one of the following things:
Change name of recipient in a sent file. I've tried using Outlook Spy (great tool) but every time I changed the recipient in PR_DISPLAY_TO_W it returned the following error:
Could not edit the property: HrSetOneProp returned MAPL_E_COMPUTED
Attaching a file to a sent email file. (I don't know if this one is possible, but would be useful if it was.)
I appreciate any responses.
PR_DISPLAY_TO / CC / BCC are computed properties. The store provider updates them whenever recipients list is modified.
Use the MailItem.Recipients collection to modify the recipients.
MailItem.Attachments.Add.

Mule 3.5.0 - How to move a file to an 'Failed' directory and send email when an exception is thrown during processing

I have Mule flow that is reading a file (csv) from an input directory and inserting records into a database. I'd like to know how to move this file to a 'failed' directory and send a notification email should an error occur in the flow. Currently my flow is as follows:
<flow name="mainFlow" doc:name="mainFlow" processingStrategy="synchronous">
<file:inbound-endpoint path="src/test/input" moveToDirectory="src/test/backup" responseTimeout="10000" doc:name="input-file" connector-ref="inputFile"/>
<READS FILE INTO DATABASE>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<file:outbound-endpoint path="src/test/error" doc:name="error-output-file"/>
</catch-exception-strategy>
</flow>
Ideally, when the file is moved to the 'failed' directory, it has the same name as the original file with 'error' appended to beginning. I've not yet attempted the email notification as I'm unsure as to how to approach this. Any help/guidance would be greatly appreciated, thanks in advance!
The original file name is available in message properties, so you can use outputPattern="error#[header:originalFilename]" in the file outbound. If your method for reading the file content into database loses the original file content, you could set a variable to hold the content right after you have read the file, and then set the variable as payload before writing the into the error directory in the exception handler.
UPDATE: For the email part, you have several options: basically you just set your email message content as payload and then send it with Mule SMTP outbound, or some email service like Mailgun that offers a simple REST API. It is really quite simple if you just have a suitable email provider.

VBScript to modify email content type

I have incoming email set up for SharePoint 2010, and am sending forms from InfoPath using that method, with SMTP server set up on the SharePoint Server machine. It seems easier than elevating the permissions of an anonymous user with the InfoPath code-behind option. I also tried a custom method of sending the emails but was unable to find a way to send the form data along with the email message using the InfoPath 2010 code-behind option. So, I found another way, using the advice from SharePoint UK's website.
My problem is that while removing the x-mailer header actually solved my problem regarding whole email messages, it did not allow the attached form data to be sent to the library. The message would be imported and then just disappear if I did not have the "Save original e-mail" setting enabled. Inspecting messages in the drop folder I found they had a content type of "multipart/related" and if I edited them with NotePad++ I could change that to "multipart/mixed" and the attached form data would then be imported as desired.
So I went about trying to modify the VB Script to make this happen BUT now nothing happens with the script at all. Clearly I'm doing something wrong with it and VBScript really isn't my area of expertise. Maybe it's just not possible to edit those fields or maybe I need to attack it from a different angle. How can I get my VBScript to edit the content type for these emails?
CODE:
Set shell = CreateObject("WScript.Shell")
shell.LogEvent 4, "starting mail filter"
if instr(iMsg.Fields("urn:schemas:mailheader:content-type"), "related") > 1 then
Dim logMsg = "Mail Type: " & iMsg.Fields("urn:schemas:mailheader:content-type")
Dim tempType = Replace(iMsg.Fields("urn:schemas:mailheader:content-type"), "related", "mixed")
shell.LogEvent 4, iMsg.Fields("urn:schemas:mailheader:content-type")
iMsg.Fields.Delete("urn:schemas:mailheader:content-type")
iMsg.Fields.Item("urn:schemas:mailheader:content-type") = tempType
iMsg.Fields.Update
shell.LogEvent 4, iMsg.Fields("urn:schemas:mailheader:content-type")
end if
shell.LogEvent 4, "end mail filter"
iMsg.DataSource.Save
EventStatus = 0
I looked into this in greater detail and found that the content-type property of an email message is one of the many that is read-only using this particular vbscript library. So, I would have to find some other way of editing the file, and the work involved is more than what it would take to find an alternate solution that skipped email altogether. Therefore, I am abandoning the plan of using email in this case. If you take something away from this, let it be that there are read-only properties for the mail message object in this script.