I am trying to make the email look like it came from a specific user in our company for an automated customer email. For some reason, I can't change "FROM" to look like anyone other than the account I log into gmail with.
I know that a PHP mail library can address the FROM address without any problems, but for some reason I cannot in python. We have an enterprise gmail account if that helps.
Here is the code I'm using
import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.MIMEImage import MIMEImage def sendFollowupEmail(html): msg = MimeText('body') msg['Subject'] = 'subject' msg['From'] = "THIS IS THE EMAIL I WANT TO CHANGE@domain.com " msg['To'] = " client@client.com " username = ' accessaccount@gmail.com ' password = 'password' server = smtplib.SMTP('smtp.gmail.com:587') server.starttls() server.login(username,password) server.sendmail(me, you, msg.as_string()) server.quit() if __name__ == '__main__': sendFollowupEmail("test123")
Here is the PHP that will let you go from the address to what you want
function sendFollowUpEmail($options) { $host = 'smtp.gmail.com'; $username = " accessaccount@gmail.com "; $password = "password"; $port = 465; echo error_reporting(E_STRICT); require_once('PHPMailer/class.phpmailer.php'); $mail = new PHPMailer(); $body = $options['body']; $mail->IsSMTP(); $mail->IsHTML(true); $mail->SMTPAuth = true; $mail->SMTPSecure = "ssl"; $mail->Host = $host; $mail->Port = $port; $mail->Username = $username; $mail->Password = $password; $mail->SetFrom($options['from'], $options['from']); if($options['bcc']!='') { $mail->AddBCC($options['bcc'], $options['bcc']); }
source share