Trouble downloading and emailing a file

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 :slight_smile:

1 Like

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

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

This worked perfectly! Thank you.

Now onto the Mailgun part.

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} 

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}

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?

Did you try using this?

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.

Get Binary File worked. Thanks for all the help Tim!

1 Like