I tried to follow the steps in https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-14-04
but when I am in my DigOcean droplet and I try to pip install postfix I get ERROR: Conld not find a version that satisfies the requirement postfix (from versions: none).
I also tried to follow the steps in https://www.rosehosting.com/blog/how-to-setup-mail-server-with-virtual-domains-using-postfix-dovecot-and-opendkim/ and I entered command ufw allow 587 with response: Rules updated Rules updated (v6), but when I enter ufw app list all I get is Available applications: OpenSSH I have already installed mailutils the code I’m trying to run is this (which works fine from my local laptop, just not from code running on my DO droplet). What I’m trying to achieve is sending updates to myself in my email to keep abreast of what’s happening in my droplet program.
import smtplib import mimetypes from email.message import EmailMessage def send_mail(body_msg, attmnt_file_loc=None): mail_obj = EmailMessage() mail_obj['Subject'] = 'This email contains an attachment' mail_obj['From'] = "email@example.com" mail_obj['To'] = 'firstname.lastname@example.org' mail_obj.set_content(body_msg) if attmnt_file_loc!=None: with open(attmnt_file_loc, 'rb') as fp: file_data = fp.read() maintype, _, subtype = (mimetypes.guess_type(attmnt_file_loc) or 'application/octet-stream').partition("/") mail_obj.add_attachment(file_data, maintype=maintype, subtype=subtype, filename=attmnt_file_loc) s = smtplib.SMTP('smtp.gmail.com', 587) s.starttls() s.login("email@example.com", "mygmailpassword") s.send_message(mail_obj) s.quit()
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.