'In Google cloud function, have FileNotFoundError: [Errno 2] No such file or directory: '/usr/sbin/sendmail': '/usr/sbin/sendmail'

I want to send email with attachments using a python script in Google Cloud Function Here is the code:

def send_mail(text, from_user, to_user, subject):
    print ("SENDING EMAIL....")
    msg = MIMEMultipart()
    msg['From'] = from_user
    msg['To'] = ", ".join(to_user)
    msg['Subject'] = subject
    msg.attach(MIMEText(text, 'plain'))
    p = MIMEBase('application', 'octet-stream')
    attachment = open(join_path(OUTPUT_FILE_DIR, OUTPUT_FILENAME), "rb")
    p.add_header('Content-Disposition', "attachment; filename= %s"
                 % OUTPUT_FILENAME)
    p.set_payload(attachment.read())
    encoders.encode_base64(p)
    msg.attach(p)
    attachment.close()
    proc = Popen(['/usr/sbin/sendmail', '-t'], stdin=PIPE)
    proc.communicate(msg.as_string())
    return

And got this error: FileNotFoundError: [Errno 2] No such file or directory: '/usr/sbin/sendmail': '/usr/sbin/sendmail'

Is this proc legal in gcp? or Is there any replacement for it? Thank you so much



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source