How to download attachment from email using Robotframework - download

I want to download attachment from email in robotframework.But in imapLibrary there is not keyword defined for download attachment.
I can read email body but didn't fine any solution to download attachment
enter code here
open mailbox host=imap.gmail.com
user=abc#gmail.com
password = secret
${LATEST}=wait for email
sender=xyz#gmail.com timeout=10
${body} = get email body ${LATEST}
# log to console ${body}
# Remove String Using Regexp ${LATEST} [^WA ID]
convert to string ${body}
log to console ${body}
close mailbox
I want to download attachment from email in robotframework.But in imapLibrary there is not keyword defined for download attachment.

Related

how to add tmp directory to amazon ses email in bash script?

I have a temp directory containing two files
#Creating a temporary directory to figure out the size
tmpSizeDir=`mktemp -d`/
trap "rm -rf $tmpSizeDir" EXIT
cp -vf "${DIRECTORY}${FILE_NAME}.csv" $tmpSizeDir
cp -vf "${DIRECTORY}${FILE_NAME}.PDF" $tmpSizeDir
I also have code to send an amazon ses email
echo "{ \"Subject\": { \"Data\": \"$subject\", \"Charset\": \"UTF-8\"}, \"Body\": { \"Text\": { \"Data\": \"$body\", #\"Charset\": \"UTF-8\" } } }" > message.json
aws ses send-email --from $MAIL_SENDER --recipient file://tmpDestinationDir --message file://message.json
How do I add a directory as an attachment to an amazon ses email?
To do it: firstly you have to change the method that you are using.
aws ses send-email is not suited for attachments. If you want to use attachments, you have to use send-raw-email.
Here is the documentation for the CLI: https://docs.aws.amazon.com/cli/latest/reference/ses/send-raw-email.html
To send a directory: firstly create a zip archive, then convert the zip archive to base64 and add it to the content of the email. Afterwards, the rest in your case stays almost the same. The one thing that you have to take into account is that in sending the raw emails you are providing by yourself all of the headers, values etc, so you will have to convert your message a bit.

How to send html mail with Content-ID header using mutt in command line

I was trying to send a html mail with images. But I am not familiar with mail headers, how can I add a image tag using cid, i.e. attach an image and make it shown in the html content?
<img src="cid:x">
This is my testing command:
mutt -s "test" jason#example.com \
-e "set content_type=text/html" \
-a /path/to/image <<MAIL
<img src="cid:0">
MAIL
It seems that this is a new feature onging in neomutt project.
Currently there's no way to add Content-ID header for attachments.
See PR: https://github.com/neomutt/neomutt/pull/2049.

Slack API file.upload to a user?

I'm trying to follow the tutorial found here https://api.slack.com/methods/files.upload .
curl -F file=#example.txt -F "initial_comment=I play the drums." -F channels=C024BE91L -F thread_ts=1532293503.000001 -H "Authorization: Bearer xoxp-xxxxxxxxx-xxxx" https://slack.com/api/files.upload
I'm able to upload files to a specific channel. However, how do I upload files to a user through direct message?
Similar to how sending direct messages work you can simply use the user ID for the channel and the file will be uploaded in a direct message channel between that user and the owner of the token.
Alternatively you can first open a direct message channel from your app with im.open and then use the channel ID of that IM in files.upload.

Send mail using mpack without attachment

How can I send mail without attachment?
mpack -s 'SUBJECT' message.txt $To
This shows the message.txt file sometimes as a body while receiving mail and sometimes it shows file attachment while receiving the same mail. I need to show always text in this file as a mail body.

Access Slack files from a slack bot

I need a slack bot that's able to receive and save files send from slack chatrooms.
The problem is: slack doesn't send file contents, but an array of links pointing to the file. Most of them, including download link are private and cannot be accessed via bot. It does send one public link, but that link points at the file preview, which does not have the file itself (here's an example).
How can I access uploaded files via bot?
You can access private URLs from your bot by providing an access token in the HTTP header when you are doing you CURL request.
Your token needs to have the scope files.read in order to get access.
The format is:
Authorization: Bearer A_VALID_TOKEN
Replace A_VALID_TOKEN with your slack access token.
I just tested it with a simple PHP script to retrieve a file by its "url_private" and it works nicely.
Source: Slack API documententation / file object / Authentication
Example for using the Python requests library to fetch an example file:
import requests
url = 'https://slack-files.com/T0JU09BGC-F0UD6SJ21-a762ad74d3'
token = 'xoxp-8853424449-8820034832-8891394196-faf6f0'
requests.get(url, headers={'Authorization': 'Bearer %s' % token})
for those wanting to accomplish this with Bash & cURL, here's a helpful function! It will download the file to the current directory with a filename that uniquely identifies the file, even if the file has the same name as others in your file listing.
function slack_download {
URL="$1";
TOKEN="$2"
FILENAME=`echo "$URL" | sed -r 's/.*\/(T.+)\/([^\/]+)$/\1-\2/'`;
curl -o "$FILENAME" -H "Authorization: Bearer $TOKEN" "$URL";
}
# Usage:
# Downloads as ./TJOLLYDAY-FANGBEARD-NSFW_PIC.jpg
slack_download "https://files.slack.com/files-pri/TJOLLYDAY-FANGBEARD/NSFW_PIC.jpg" xoxp-12345678901-01234567890-123456789012-abcdef0123456789abcdef0123456789
Tested with Python3 - just replace SLACK_TOKEN with your token.
Downloads and creates an output file.
#!/usr/bin/env python3
# Usage: python3 download_files_from_slack.py <URL>
import sys
import re
import requests
url = " ".join(sys.argv[1:])
token = 'SLACK_TOKEN'
resp = requests.get(url, headers={'Authorization': 'Bearer %s' % token})
headers = resp.headers['content-disposition']
fname = re.findall("filename=(.*?);", headers)[0].strip("'").strip('"')
assert not os.path.exists(fname), print("File already exists. Please remove/rename and re-run")
out_file = open(fname, mode="wb+")
out_file.write(resp.content)
out_file.close()

Resources