Need to send email with Attachment from Matillion Tool - email-attachments

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)

Related

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.

How to send mail with attachments in Plone using a template approach?

I've been reading the official docs about sending emails from Plone using some templates, and it's working so far.
My question is: how do I add attachments using the template approach?
The MailHost.send command takes both python (unicode) strings and email.Message objects. That means you can use the python email package to construct a proper MIME message with attachments.
The standard library includes a great page of examples; any text can still be generated by templates just like in the documentation you linked.
Use Python's email module.
Examples:
http://docs.python.org/library/email-examples.html
The composed messages can be passed to context.MailHost (the MTA of Zope).
It is in every case better generating and sending out emails from the Python level instead of using the old DTML sendmail facade...don't use it.
This is my solution, maybe it is not the best:
create a mime_file DTML Method in portal_skin/custom:
<dtml-mime type="text/text; charset=utf-8" encode="7bit">
<dtml-var "text">
<dtml-boundary type="application/octet-stream" disposition="attachment"
filename_expr="nomefile"><dtml-var "file"></dtml-mime>
Call it (for example from a Python Script) as:
message = context.mime_file(file=a_file, text=message, nomefile='attach_name.pdf')
context.MailHost.send(message, mTo, mFrom, mSubj)
where a_file is the content of the file.
inspired by:
http://www.zope.org/Members/visibleoffice/HowTo.2003-10-22.1455
This is a quick&dirt solution, using Python Scripts.

Sending email with attachment

I've a custom form (created with form API) that need send an uploaded file by email. The current form submit handler sends the email without attachment using drupal_mail().
So I'm looking for a solution to properly send email with attachment from Drupal. Mime Mail seems an overkill because HTML mail, templating and its other features are not required. But the only other alternative I see is to set the appropriate headers and serialize the attached file in the mail body when processing the mail in my hook_mail() implementation.
Did I miss anything? Is there any module to handle this?
Mimemail is the easiest solution here. Be it an overkill or not, it will allow you to get it done with a single function call.
If you insist, you may have your homemade attachment sender: base64 encode your attachment(s), add them to the mail body, add the correct headers and you're done.
You can use mime mail and force the message body to be sent in plaintext format. Here is an excerpt from the module's readme file:
USAGE
This module may be required by other modules, but is not terribly
useful by itself. Once installed, any module can send messages by
calling the mimemail() function:
$sender - a user object, text email address or an array with name, mail
$recipient - a user object, text email address or an array with name, mail
$subject - subject line
$body - body text in HTML format
$plaintext - boolean, whether to send messages in plaintext-only (default FALSE)
$headers - a keyed array with headers (optional)
$text - plaintext portion of a multipart e-mail (optional)
$attachments - array of arrays with the file's path, MIME type (optional)
$mailkey - message identifier
return - an array containing the MIME encoded message
The key thing being to set the $plaintext argument to TRUE. Now you can have your cake and eat it too.
You could always have a look at the Swift Mailer module which lets you send HTML (MIME) e-mails, e-mails with inline images and e-mails with attachments. It is also cabable of automatically generating plain text versions based on the HTML e-mail version, which in the end will let the user's e-mail client display the preferred version (HTML or plain text).
The Swift Mailer module is available on http://drupal.org/project/swiftmailer.
For the record : I'm the author and maintainer of the module.
The Webform module allows you to create a form and has a file option which can be used as an attachment. All available form components are listed on the module's manual page.
Once installed Webform will appear as a content type. Once you have saved the fundamentals, such as the title and the email to address, you will have the ability to add the required form components.
Add a component of type 'file', ensuring the 'email' (to recipient) option is ticked, and you will then be able to customize the permitted file types, extensions, sizes and upload folder.
You could use the Zend Framework.
function sendEmail($params){
ini_set('include_path', 'inc/');
require_once ('inc/Zend/Mail.php');
$mail = new Zend_Mail();
$mail->setSubject( $params['subject'] );
$mail->setBodyText( $params['bodyText'] );
$mail->setBodyHtml( $params['bodyHtml'] );
$mail->setFrom( $params['fromEmail'], $params['fromName'] );
$mail->addTo( $params['toEmail'], $params['toName'] );
// Finally, add an attachment
assert( file_exists($params['attachFile']) );
$at = $mail->addAttachment(file_get_contents($params['attachFile']));
$at->type = $params['attachType'];
$at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$at->filename = $params['attachName'];
$mail->send();
}

Changing filename of attachment in CFMail

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 )#"
/>

Using the Microsoft SMTP Server's Dropfolder

I have set up Microsoft SMTP server so it will store all incoming email in a dropfolder.
I want to process, using c#, incoming mail based on the sender, recipient, and subject line. If possible, I also want to create a plain text preview of the email.
So, there are two parts to this problem.
I'm guessing a FileSystemWatcher
would be adequate for providing
notification of incoming mail.
How to parse the headers and body text from the .eml file; is there an existing library or any good documentation on the format?
Thanks for any help.
Yes - thats true
I used this: http://www.lumisoft.ee/lswww/ENG/Products/Mail_Server/mail_index_eng.aspx?type=info
It's a Mailserver written in C# with an API you can use without using the Mailserver
EDIT: Found a code snippet:
LumiSoft.Net.Mime.Mime m = LumiSoft.Net.Mime.Mime.Parse(mailfile);
Console.WriteLine("Read message from: " + m.MainEntity.From);
Console.WriteLine("To: " + m.MainEntity.To[0]);