gpt4 book ai didi

php - Python使用gmail从不同地址发送电子邮件

转载 作者:可可西里 更新时间:2023-10-31 22:57:23 25 4
gpt4 key购买 nike

我试图让一封电子邮件看起来像是来 self 们公司内的特定用户,以便自动发送客户跟进电子邮件。出于某种原因,我无法将“FROM”更改为除了我登录 gmail 时使用的帐户之外的任何人。

我知道 PHP 邮件程序库可以毫无问题地从任何人那里获取 FROM 地址 - 但由于某些原因我不能在 python 中使用。如果有帮助,我们有一个企业 gmail 帐户。

这是我正在使用的代码

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")

这是允许您将地址更改为您想要的任何内容的 PHP

function sendFollowUpEmail($options) {

/*
* Send an email to a person or group.
* Dependencies: PHPMailer
* options: {
* 'to' -> who to send the email to,
* 'from'-> who the email was sent from,
* 'subject'-> subject of the email,
* 'body' -> the body of the email
* }
*/
$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']);
}

//$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->Subject = $options['subject'];
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$address = $options['to'];
$mail->AddAddress($address);
$mail->send();

最佳答案

添加到消息中

msg['Reply-To'] = "THIS IS THE EMAIL I WANT TO CHANGE@domain.com"

编辑

您可以做的一件事是在您的帐户和导入 gmail 中添加返回电子邮件。并选择它而不是别名。这将允许您从您的主帐户发送电子邮件作为其他帐户。使用其他帐户的发件人地址

关于php - Python使用gmail从不同地址发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11193482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com