TommiT
November 18, 2020, 8:04am
#1
Hey! I’m new to Robocorp and Robot framework itself.
I have a task where I have to navigate a UI to download a file and then email that file and I’m having a bit of trouble doing that.
First of all the file I download doesn’t appear if I use the Open Headless Chrome Browser
keyword but it does appear if I use the Open Available Browser
keyword but it appears in the Downloads folder of my machine.
Second, I am trying to use Mailgun to email the downloaded file. What would be the best way to use Mailgun within Robocorp Cloud?
Thanks
1 Like
Tim
November 18, 2020, 8:53am
#2
You can control the download directory like this: https://robocorp.com/docs/development-howtos/browser/how-to-change-browser-download-directory
Note the requirement for rpaframework 6.4.0+
1 Like
Tim
November 18, 2020, 9:01am
#3
For having your robot send e-mails via Mailgun I would use their API:
And call it via our HTTP library (RPA.HTTP ):
Example here https://robocorp.com/docs/development-howtos/http/http-api-robot-tutorial
3 Likes
TommiT
November 19, 2020, 12:38pm
#4
This worked perfectly! Thank you.
Now onto the Mailgun part.
TommiT
November 19, 2020, 1:45pm
#5
Hey,
How should I format the HTTP request?
I’m currently trying it like this and it doesn’t work.
Send test email
[Tags] post post-cert
${auth}= Create List api API_KEY
Create Session Mailgun https://api.eu.mailgun.net/MAILGUN_DOMAIN auth=${auth}
&{data}= Create Dictionary
... from=TESTMAILER <mailgun@MAILGUN_DOMAIN>
... to=TEST.RECIPIENT@TEST.COM
... subject=Test
... text=Test
&{headers}= Create Dictionary Content-Type=application/x-www-form-urlencoded
${resp}= Post Request Mailgun /messages data=${data}
TommiT
November 20, 2020, 1:05pm
#6
I got this working with these changes.
Send test email
[Tags] post post-cert
Create Session Mailgun https://api:API_KEY@api.eu.mailgun.net/v3/MAILGUN_DOMAIN
&{data}= Create Dictionary
... from=TESTMAILER <mailgun@MAILGUN_DOMAIN>
... to=TEST.RECIPIENT@TEST.COM
... subject=Test
... text=Test
${resp}= Post Request Mailgun /messages data=${data}
Log ${resp.content}
TommiT
November 20, 2020, 1:08pm
#7
Now I’m having trouble adding an attachment file to the message.
Send test email
${local_files}= List Files In Directory ${DOWNLOAD_DIRECTORY}
[Tags] post post-cert
Create Session Mailgun https://api:API_KEY@api.eu.mailgun.net/v3/MAILGUN_DOMAIN
&{data}= Create Dictionary
... from=TESTMAILER <mailgun@MAILGUN_DOMAIN>
... to=TEST.RECIPIENT@TEST.COM
... subject=Test
... text=Test
&{files}= Create Dictionary
... attachment=${DOWNLOAD_DIRECTORY}/${local_files}[0]
${resp}= Post Request Mailgun /messages data=${data} files=${files}
Log ${resp.content}
The code above only sends an attachment file with the path to the file I’m trying to send as text.
Is there a way to send the actual file as an attachment in the message?
TommiT
November 20, 2020, 1:33pm
#9
Yes I got the attachment to be sent but the contents of the attachment are just the path to the file. Now I’m trying to use Get File
to fetch the contents of the file and then sending that as the attachment, but once I try to open the attachment it is corrupted according to Excel.
TommiT
November 20, 2020, 3:00pm
#10
Get Binary File
worked. Thanks for all the help Tim!
1 Like