我只是想在我的项目中添加电子邮件验证功能。我已经在网上进行了很多搜索。但是没有得到答案。请有人帮助我。
您可以使用类似这样的内容:
using System.Text.RegularExpressions;
public static Boolean IsEmailValid(string EmailAddr)
{
if (EmailAddr != null || EmailAddr != "")
{
Regex n = new Regex("(?<user>[^@]+)@(?<host>.+)");
Match v = n.Match(EmailAddr);
if (!v.Success || EmailAddr.Length != v.Length)
{
return false;
}
else
{
return true;
}
}
else
{
return false;
}
}
使用SMTP服务器向客户端发送电子邮件。
要从MVC
应用程序发送电子邮件,您可以在SMTP
代码或C#
中指定web.config
详细信息。在web.config
:
<mailSettings>
<smtp>
<network host="your.smtp.server.com" port="25" />
</smtp>
</mailSettings>
</system.net>
在您的代码中:
SmtpClient client=new SmtpClient();
否则,请在代码中完成:
SmtpClient client=new SmtpClient("some.server.com");
//If you need to authenticate
client.Credentials=new NetworkCredential("username", "password");
Now you create your message:
MailMessage mail = new MailMessage();
mai.From = "yourNam@yourDoman";
mail.To.Add("yourClient@someDomain");
mail.Subject = "Your Subject";
mail.Body = "<h1>Your Email content here. You can use html and css here";
发送电子邮件:
client.Send(mail);