SMTP can accepts emails with false sender name

2019-09-06 16:13发布

I'm using SMTPClient for sending emails to a SMTP server. But with Send method I can specify any false sender name or email. How can I prevent this?

4条回答
家丑人穷心不美
2楼-- · 2019-09-06 17:04

It's the job of your mail server to decide on what it accepts as a sender email address - that's just a matter of policy.

There is no 'true' email address for a mail client, so nothing that can be enforced at the client.

查看更多
姐就是有狂的资本
3楼-- · 2019-09-06 17:09

I think that should be the SMTP server's role to decide whether a sender name is valid or not. In fact, introducing it in your code is a violation of the DRY rule since you'd be replicating the SMTP configuration.

As you can see in http://msdn.microsoft.com/en-us/library/swas0fwc%28v=VS.90%29.aspx, you should only be prepared to catch SmtpExceptions and properly display them to your software's user.

查看更多
甜甜的少女心
4楼-- · 2019-09-06 17:10

You can't do anything about it in the SmtpClient.

You can do something about it in your application. Send a verification email that the user must click on to validate it's email.

You can do something about it in your smtp server. Check the MX record or the defined SPF policies against the sender domain/ip address.

查看更多
Melony?
5楼-- · 2019-09-06 17:15

SMTP is a mail transfert protocol (as the name implies). It's not in charge of authenticating the sender. To authenticate the sender, your need to use certificates, which SMTP supports, but again, just as a mean of transfert. The program itself needs to have the logic to authenticate the sender with the certificate.

You can also use authentication, but in that case it'll be the SMTP server that will match the username/password with an email address.

查看更多
登录 后发表回答