SMTP未在gmail业务帐户中发送电子邮件
这段代码在gmail个人帐户中运行良好,但当我尝试使用gmail商业帐户时,它不起作用并不断给出错误。5.5.1需要认证SMTP未在gmail业务帐户中发送电子邮件,smtp,gmail,google-workspace,Smtp,Gmail,Google Workspace,这段代码在gmail个人帐户中运行良好,但当我尝试使用gmail商业帐户时,它不起作用并不断给出错误。5.5.1需要认证 void SendEmail() { DataTable data = GetData(); DataTable email_data = GetEmailData(); data.TableName = "Employee_Data"; using (XLWorkbook wb = new XLWorkbook()) {
void SendEmail()
{
DataTable data = GetData();
DataTable email_data = GetEmailData();
data.TableName = "Employee_Data";
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(data);
using (MemoryStream memoryStream = new MemoryStream())
{
wb.SaveAs(memoryStream);
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
String from = "seong@abcd.net";
for (int i = 0; i < email_data.Rows.Count; i++)
{
String to = email_data.Rows[i][0].ToString();
using (MailMessage mm = new MailMessage(from, to))
{
mm.Subject = "Employees Attachment";
mm.Body = "Employees Exported Attachment";
mm.Attachments.Add(new Attachment(new MemoryStream(bytes), "Employees.xlsx"));
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential();
credentials.UserName = "seong@abcd.net";
credentials.Password = "1234";
smtp.UseDefaultCredentials = true;
smtp.Credentials = credentials;
smtp.Port = 587;
smtp.Send(mm);
}
}
}
}
}
void sendmail()
{
DataTable data=GetData();
DataTable email_data=GetEmailData();
data.TableName=“员工数据”;
使用(xl工作簿wb=new xl工作簿())
{
wb.工作表.添加(数据);
使用(MemoryStream MemoryStream=new MemoryStream())
{
wb.SaveAs(内存流);
byte[]bytes=memoryStream.ToArray();
memoryStream.Close();
字符串from=”seong@abcd.net";
对于(int i=0;i
我解决了这个问题。
如果您想使用SMTP,该帐户不应在gmail中使用第二次验证
我无法控制这些东西,我要求管理员允许不使用第二次验证。
因此,我可以使用SMTP处理该帐户。我解决了这个问题。
如果您想使用SMTP,该帐户不应在gmail中使用第二次验证
我无法控制这些东西,我要求管理员允许不使用第二次验证。
因此,我可以使用SMTP处理该帐户。用于业务Gsuite的SMTP方法
require_once('class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true;
$mail->Port = 587;
$mail->Host = "smtp.gmail.com";
$mail->Username = "Enter the user ID"; // SMTP account username
// SMTP account password
$mail->Password = "Enter your password";
$mail->SetFrom('Enter the User ID', 'Subject');
$mail->AddReplyTo("Enter the User ID", "Subject");
$mail->AddAddress($to, "Name");
$mail->Subject = "Contact Enquiry";
$message = '';
$mail->MsgHTML($message);
if($mail->Send()){
$mail->ClearAddresses();
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
业务Gsuite的Smtp方法
require_once('class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true;
$mail->Port = 587;
$mail->Host = "smtp.gmail.com";
$mail->Username = "Enter the user ID"; // SMTP account username
// SMTP account password
$mail->Password = "Enter your password";
$mail->SetFrom('Enter the User ID', 'Subject');
$mail->AddReplyTo("Enter the User ID", "Subject");
$mail->AddAddress($to, "Name");
$mail->Subject = "Contact Enquiry";
$message = '';
$mail->MsgHTML($message);
if($mail->Send()){
$mail->ClearAddresses();
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
尝试添加mm.Header=“From:”此外,我不确定您的smtp.Host是否为smpt.gmail.com,可能为smpt.abcd.net您应该将您的google帐户配置为较低权限。我实际上没有尝试过此操作,但这些链接可能有助于尝试添加mm.Header=“From:”此外,我不确定您的smtp.Host是否为smpt.gmail.com,可能是smtp.abcd.NET您应该将您的google帐户配置为较低权限。我实际上没有尝试过此操作,但这些链接可能有助于登录您的Gmail帐户:转到-->设置-->转发和POP/IMAP-->启用IMAP,然后转到Gmail帐户设置-->安全-->不太安全的应用程序访问(打开)。用于商业gmail的SMTP方法将非常有效。登录您的gmail帐户:转到-->设置-->转发和POP/IMAP-->启用IMAP,然后转到gmail帐户设置-->安全-->不太安全的应用程序访问(打开)。商业gmail的SMTP方法将完美工作。