Hello,
I’m trying to write a custom server side script that automatically attaches File pieces that are linked to items to an email that is being sent when a form submits. Here is the usage case:
The email is a Request for Quotation that gets sent to a supplier. I need to include the RFQ (which is a printed version of the Request for Quotation doctype), plus other files for all the items that are being quoted (some pdf and other file formats). I have attached the appropriate files in the Item doctype, and can call them up as needed.
The place I am having an issue is with the actual frappe.sendmail command. I can attach the pdf of the doctype, but not the other files. Here is what I have:
Attaching the pdf of the current doctype (works):
my_attachments = [frappe.attach_print(self.doctype, self.name, file_name=self.name)]
Sending the email (works):
frappe.sendmail(
recipients=[self.supplier_email],
subject=self.title,
message=self.comments,
reference_doctype=self.doctype,
reference_name=self.name,
attachments=my_attachments
)
Function that tries to get the attached file
def create_attachment(filename):
file = frappe.get_doc("File",filename)
frappe.msgprint(_("Adding {0}".format(file.file_name)))
with open(file.file_url, "rb") as fileobj:
filedata = fileobj.read()
out = {
"fname": file.file_name,
"fcontent": filedata
}
The error I’m getting is:
I realize that the path I’m specifying probably isn’t complete, which is why it isn’t finding it, but I can’t seem to find where this path goes, and I’m not sure this is the right way to do it even if I was to specify the right file.
Any help would be greatly appreciated!