ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

PDF Attachment in FrappeClient (Python API)

api

#1

I am using frappeclient in python script for sending and email (with attachment).
This is what I’m using:

frappeObj = FrappeClient('https://my_website,'administrator','password');
print(frappeObj);
att="<html><head></head><body><h1>Attachment In Process</h1></body></html>";
attachment=[{"file_url":"my_file_path.pdf","name":"1a0ec47280","is_private":1}]
 
args={ 
 "sender":"email@gmail.com",
 "sendername":"nikhil",
 "recipients":"email@gmail.com",
 "content":"test",
 "subject":"Test-mail-002",
 "send_email":"1", 
 "communication_medium":"Email",
 "Sent_or_received":"Sent",
 "read_receipt":"0",
 "print_html":att,
 "attachments":attachment
 }
print(args);
response =frappeObj.get_api('frappe.core.doctype.communication.email.make',args);
print(response);

I actually want to send directly my pdf in attachment but on passing it to print_html it is passing it as NULL . But on passing an html, it is converting it to pdf and sending. That is what I want to override. If not using that parameter (print_html) results into error.
Already tried attaching pdf directly but it is not getting attached .
Any help/suggestions will be deeply appreciated.

Thank You


Convert Email Body into Attached PDF
#3

Any suggestions will be hugely appreciable. I seriously need help in this

Thank You


#4

Any ??


#5

Hi, I’m a bit confused why did you use FrappeClient it seems old, last update is about 3 years ago.

Did you tried to send Email from python outside Frappe Framework?

If it is, why don’t you directly use Email Delivery Service API? Such as sparkpost api.

If you tried to sending email from python inside Frappe Framework, I normally use frappe.sendmail.

    frappe.sendmail(
        recipients=['email1@gmail.com', 'email2@gmail.com'],
        sender='email0@gmail.com',
        template='mail-template',
        # args is pass to template in apps/apps/templates/emails/mail-template.html
        args={
            'text': 'Hello',
            'contact': 'Josh',
        },
        subject='Hi, World',
        now=True,
        )

#6

I am using external script for doing so, in which i need to mention the doctype and attachment existed there to fetch and then append it to the mail. Any documents / help for doing so will be appreciated. Also am having issue with finding the frappe module inside the framework (as on external script frappe module not found error came and i dont get external library named frappe too. Please suggest regarding that too)


#7

Solved. Need to pass syntax as

attachments: '["name"]'

where name is fetched from File List (got form filtering with attached to name field)


Api method for sending mail (external script)
Syntax for adding attachment to frappeclient method