c# - 使用其他邮件服务器时发送电子邮件时出错,期望 gmail
问题描述
我正在尝试从邮件地址(hassan@creativesolutionzone.com)发送电子邮件,但它没有发送未处理的异常:
System.net.mail.smtp 异常:邮箱不可用。服务器响应被拒绝访问 - HELO 名称无效(请参阅 RFC2821 4.1.1.1)
这是代码..
private void sendMail()
{
login = new NetworkCredential(txtUsername.Text, txtPassword.Text);
client = new SmtpClient(txtSMTP.Text);
client.Port = Convert.ToInt32(txtport.Text);
client.EnableSsl = chkSSL.Checked;
client.Credentials = login;
msg = new MailMessage { From = new MailAddress(txtUsername.Text + txtSMTP.Text.Replace("mail.", "@"), "Creative Solution Zone", Encoding.UTF8) };
msg.To.Add(txtTO.Text);
if (!string.IsNullOrEmpty(txtCC.Text))
msg.To.Add(new MailAddress(txtCC.Text));
msg.Subject = txtSubject.Text;
msg.Body = txtMessege.Text;
msg.BodyEncoding = Encoding.UTF8;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.Normal;
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
client.SendCompleted += new SendCompletedEventHandler(SendCompleteCallBack);
string userState = "Sending...";
client.SendAsync(msg, userState);
}
private static void SendCompleteCallBack(object sender, AsyncCompletedEventArgs e)
{
if (e.Cancelled)
MessageBox.Show(string.Format("{0} Send Cancelled ", e.UserState), "Messgae", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (e.Error != null)
MessageBox.Show(string.Format("{0}", e.Error), "Messgae", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("Your Message Has Been Successfully Sent", "Messgae", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
谁能帮我解决这个问题?
注意:当我尝试从我的 Gmail 帐户发送邮件时,代码运行良好,但当我更改邮件时它无法正常工作
解决方案
推荐阅读
- python - Python3从加载文件浮动到int
- android - Firebase 云消息没有声音
- python - 在 python 中使用 list 方法看不到错误
- amazon-web-services - Freenom.com 和 AWS Amplify:亚马逊要求我“配置根域”(@ ANAME abc-whatever-xyz.cloudfront.net)-> Freenom:不允许使用通配符
- javascript - 带有 Next.js 10.0.3 的 Tailwind CSS(PostCSS 插件)在开发环境中导致 Javascript 堆内存不足错误
- algorithm - 如何将 k 独立集问题简化为 3-SAT
- python - 在 Python 中传递可选参数
- android-studio - 如何在“设置”中“在工具窗口中启动”处于活动状态时更改 Android Studio 模拟器设置?
- spring-boot - Spring Boot QueryDSL BooleanExpression - “OR”条件取决于表中的值
- javascript - 在 jQuery 数组中查找每个对象有多个元素的字符串