English 中文(简体)
为什么邮件地址是john@gmail。 电子邮件地址是否有效?
原标题:Why does MailAddress think john@gmail. is a valid email address?
最佳回答

我认为,在这种情况下,至少在RFC822。 我没有实际尝试过你的法典,因此我假定这样做。

还有其他验证电子邮件地址的方法,例如与员工和管理当局协调会服务器实际连接,并请其确认地址是有效的(如herehere)。 如果不这样做,你总是会遇到麻烦。 从个人角度来说,我认为,根据某些具体内容(除了我们可以采用的快速检查;例如你的代码)使用太多时间确认电子邮件地址是值得的,真正的检验是,如果你发出电子邮件,是否收到电子邮件。 简单的电子邮件核查可以证实这一点,尽管我知道,在所有情况下都可能不合适,但是在那些情况下,你不是幸运的。

问题回答

邮件地址的确认得到的支持非常有限,截至4.0,邮件地址的验证不支持因特网工作队的大多数相关标准。 如果你需要验证您的电子邮件地址的同质,可能的话,不使用正常的<>,我建议你看。 EmailVerification.NET, a .NET part that support all of the current standards about the subject (RFC 1123, RFC 2821, RFC 2822, RFC 3696, RFC 4291, RFC 5321 and RFC 5322). 如你需要,该构成部分甚至允许对地址进行额外测试,包括安全总局、员工和管理当局协调署和邮箱检查。

申斥: 我是这一产品的主要发展者。

Somehow fixed version, mixing MailAddress and a simple Regex to validate the host:

Static regex, SLaks

private static readonly Regex hostReg = new Regex(@"(w+).(w+)");

public bool IsMailAddress(string addParam)
        {
            try
            {
                MailAddress mail = new MailAddress(addParam);
                string address = mail.Address;

                //not handled by MailAdress, which is a shame
                return hostReg.IsMatch(mail.Host);
            }
            catch (FormatException)
            {
                //address is invalid
                return false;
            }
            catch (Exception)
            {
                return false;
            }
        }

MailAddress tries to be compatible with RFC2822 which obsoletes RFC822. When you read the source code of MailAddress you see that the end-dot it s accepted just for compatibility with some e-mail clients. Validating e-mail address with regex is not the right thing to do (see RFC2822), the best way is to implement a parser, what MailAddress did.

http://vis.microsoft.com/#System/net/System/Net/mail/DotAtomReader.cs”rel=“nofollow”>,见《邮递AddressParser 使用的DotAtomReader

不是免费解决办法,而是Cobisi s email accreditation Library可说明电子邮件是否有效,或在不同程度上有效(Syntax、IspSpecificSyntax、DeaDomain、Dns、DeamailExchangeer、Smtp、邮箱、CatchAll)。

var engine = new VerificationEngine();
var result = engine.Run("john@example.com",
                        VerificationLevel.Mailbox).Result;

if (result.LastStatus == VerificationStatus.Success)
{
    // TODO: Show a message box with the great news
}

申斥: 我与公司或项目无关。

邮箱有免费的电文。 仅需在。 因此,一体化部分非常容易,因为它们还有一个C#类别。 http://www.mail Boxvalidator.com/dotnet。 页: 1

C#类代码载于

To install MailboxValidator SingleValidation class via NuGet (https://www.nuget.org/packages/MailboxValidator.SingleValidation/), run the following command in the Package Manager Console:

Install-Package MailboxValidator.SingleValidation

那么,你就只能使用以下一类:

using System;
using System.Windows.Forms;
using MailboxValidator;

namespace TestMailboxValidatorCSharp
{
    public class TestMailboxValidatorCSharp
    {
        static void Main(string[] args)
        {
            var mbv = new SingleValidation("PASTE_YOUR_API_KEY_HERE");
            String results = "";
            try
            {
                MBVResult rec = mbv.ValidateEmail("example@example.com");

                if (rec.ErrorCode == "")
                {
                    results += "email_address: " + rec.EmailAddress + "
";
                    results += "domain: " + rec.Domain + "
";
                    results += "is_free: " + rec.IsFree + "
";
                    results += "is_syntax: " + rec.IsSyntax + "
";
                    results += "is_domain: " + rec.IsDomain + "
";
                    results += "is_smtp: " + rec.IsSMTP + "
";
                    results += "is_verified: " + rec.IsVerified + "
";
                    results += "is_server_down: " + rec.IsServerDown + "
";
                    results += "is_greylisted: " + rec.IsGreylisted + "
";
                    results += "is_disposable: " + rec.IsDisposable + "
";
                    results += "is_suppressed: " + rec.IsSuppressed + "
";
                    results += "is_role: " + rec.IsRole + "
";
                    results += "is_high_risk: " + rec.IsHighRisk + "
";
                    results += "is_catchall: " + rec.IsCatchall + "
";
                    results += "mailboxvalidator_score: " + rec.MailboxValidatorScore + "
";
                    results += "time_taken: " + rec.TimeTaken + "
";
                    results += "status: " + rec.Status + "
";
                    results += "credits_available: " + rec.CreditsAvailable + "
";
                }
                else
                {
                    results += "error_code: " + rec.ErrorCode + "
";
                    results += "error_message: " + rec.ErrorMessage + "
";
                }

                results += "version: " + rec.Version + "
";
                MessageBox.Show(results);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "
" + ex.StackTrace);
            }
        }
    }
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...