Guest
Guest

Reputation: 515

Python Error: (2, 'No such file or directory') while email file in python

I am trying to send a file through EmailMessage but I'm getting the error No such file or directory. The file is available in the mentioned directory, so why am I not able to email the file?

from django.core.mail import send_mail, EmailMessage

def email_file(recipient, title, email_msg, file_name):
    try:
        msg = EmailMessage(title, email_msg, to=recipient)
        msg.attach_file(file_name)
        msg.send()
    except Exception as exception:
        print exception.args

if __name__ == '__main__':
    excel_file = '/home/geeks/test.pdf'
    recipient = 'email'
    email_msg = 'Please find placement report of this week'
    title = 'Status Report'
    email_file(recipient, title, email_msg, excel_file)

Permission of file is

 -rw-r----- 1 geeks geeks      83079 Jan 19 02:17  test.pdf

Upvotes: 0

Views: 480

Answers (1)

burning
burning

Reputation: 2586

No such file or directory

Itself indicate the answer.

Either your file does not exist at the path you have given or it does not have enough permission to read file.

Upvotes: 1

Related Questions