gpt4 book ai didi

c# - SMTP gmail 客户端在不同的主机上工作很奇怪

转载 作者:太空宇宙 更新时间:2023-11-03 15:49:06 25 4
gpt4 key购买 nike

我用 C# 编写了以下用于发送消息的代码:

bool ret = false;
MailAddress fromAddress = new MailAddress("addressfrom@gmail.com", "Name");
string fromPassword = "MyPassw";

try
{
SmtpClient smtp = new SmtpClient
{
//Host = "smtp.gmail.com",
//Port = 587,
//EnableSsl = true,

Host = "rs.t-home.mk",
Port = 25,
EnableSsl = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new System.Net.NetworkCredential(fromAddress.Address, fromPassword)
};

System.Web.UI.WebControls.MailDefinition md = new System.Web.UI.WebControls.MailDefinition();
md.From = "addressfrom@gmail.com";
md.IsBodyHtml = false;
md.Subject = subject;
System.Collections.Specialized.ListDictionary replacements = new System.Collections.Specialized.ListDictionary();
MailMessage msg = md.CreateMailMessage("mailTo@address.com", replacements, body, new System.Web.UI.Control());//belinaljupce@belina.com.mk
smtp.Send(msg);
ret = true;
}
catch
{
ret = false;
}

在本地测试此代码时,使用此 SmtpClient 设置:

Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true

一切正常,我可以发送消息,也可以发送到我的 Gmail 帐户的“发送”文件夹中我可以看到所有来自此 SmtpClient 的发送消息

但是当我在服务器上发布此代码时,我必须在其中使用此 SmtpClient 设置:

Host = "rs.t-home.mk",
Port = 25,
EnableSsl = false

我可以发送电子邮件,正常情况下,它工作正常,但在我的 Gmail 帐户的发送文件夹中,我没有看到来自此 SmtpClient 的发送消息,尽管邮件已发送(我已经检查过,并且“mailTo@address.com”接收邮件)所以我很好奇是什么原因造成的,并想知道如何解决这个问题。

最佳答案

I can send e-mail, normally, it works fine, but into the Send folder of my Gmail account I don't see the send message from this SmtpClient, although the mail is send (I've checked, and "mailTo@address.com" receive the message) So I'm curious what causes this, and wonder how to fix this.

这是因为 rs.t-home.mk 不是 Gmail SMTP 服务器。更简单的“解决方法”是将您的 Gmail 帐户包含在密件抄送中。

关于c# - SMTP gmail 客户端在不同的主机上工作很奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26675395/

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