如何从代码发送邮件,而邮件被接收者邮件服务器拒绝 [英] How to send a mail from the code without failure that mail was rejected by receiver mail server

查看:311
本文介绍了如何从代码发送邮件,而邮件被接收者邮件服务器拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我们向用户发送自动生成的邮件。通过我们的代码。让我们考虑接收者emailid是Gmail。接收器能够从系统发送的邮件中接收邮件,即系统或生成的代码。如果他们没有设置允许,那么邮件发送失败。如何避免这种情况。如何在不被客户/用户邮件服务器拒绝的情况下发送邮件。



请帮忙。



我尝试过:



Hello,

As we send a auto generated mail to user. through our code. let us consider receiver emailid is of Gmail. then receiver have enable to receive a mail from those mails send from system i.e system or code generated. if they do not have set allow to it then mail sending is failure. How to avoid this. what should I do to send mail without rejected by client/user mail server.

please help.

What I have tried:

using (MailMessage mm = new MailMessage("trial@gmail.com", trialEmail.Text))
    {
        mm.Subject = "Send test";
        string body = "Hello " ;
        mm.Body = body;
        mm.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
        NetworkCredential NetworkCred = new NetworkCredential("trial@gmail.com", "password");
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = NetworkCred;
        smtp.Port = 587;
        smtp.Send(mm);
    }







Google帐户保障



在访问不太安全的应用程序部分下,您可以从其他设备/应用程序中启用对您帐户的访问权限...例如您的C#应用​​程序。



注意,不再有特定于应用程序部分。





一旦我在接收器中执行此设置邮件帐户然后我能够发送邮件。但问题是它是默认阻止/关闭。并且大多数用户都没有打开它。有点令人惊讶我们从亚马逊或Facebook网站收到邮件而没有启用此设置。他们为它做了什么?




Google Account Security

Under the "Access for less secure apps" section, you can enable access to your account from other devices/applications... like your C# application.

Note, there is no longer an "application specific" section.


once I do this setting in receiver mail account then I able to send mail. but problem is it is by default block/off . and most of user don't make it on. bit it was surprising we got a mails from amazon or facebook sites without enabling this setting. What they do for it?

推荐答案

你无法避免它。



设置电子邮件的收件人方面完全不受您的控制。您的电子邮件无法解决这个问题。收件人是否想要接收电子邮件完全取决于他们以及电子邮件客户端和电子邮件服务器设置。
You can't avoid it.

The settings of the recipient side of an email are completely out of your control. There is no way for your email to get around that. Whether or not the recipient wants to receive the email is entirely up to them and the email client and email server settings.


为什么它被拒绝了?这个原因驱动着你可以做的事情。如果由于未知或无效的电子邮件地址而被拒绝。然后,您可以尝试验证您是否有正确的电子邮件或查看是否存在拼写错误。



但如果拒绝是因为您的邮件服务器或域已被列入黑名单除了联系服务器的所有者之外你没什么可做的。
Why was is it rejected? This reason drives what you can do. If it was rejected because of an unknown or invalid email address. Then you could attempt to validate you have the right email or see if there is a spelling mistake.

But if the rejection is because your mail server or domain has been blacklisted not much you cam do except contact the owner of the server.


我发现答案非常简单。



add smtp .UseDefaultCredentials = true;

在NetworkCredential行之前
I found the answer it's pretty simple.

add smtp.UseDefaultCredentials = true;
before NetworkCredential line


这篇关于如何从代码发送邮件,而邮件被接收者邮件服务器拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆