如何使用SMTP发送邮件? [英] How to send Mail Using SMTP?
本文介绍了如何使用SMTP发送邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
到目前为止,我已经使用此CODE进行电子邮件验证,并使用SMTPClient发送了一封邮件.但是它不起作用,也不会发送到所述的gmail.但是我认为我的代码没有问题.我需要一些帮助来确定发送邮件的方法.
So far I have this CODE for email validation and a Mail to send Using SMTPClient However it won't work ,it won't send to the gmail stated. But i think there is no problem with my code. I need some help to make a way for sending Mail .
string validEmailPattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
+ @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
+ @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";
Regex ex = new Regex(validEmailPattern, RegexOptions.IgnoreCase);
if (ex.IsMatch(TextBox1.Text))
{
MailMessage m = new MailMessage();
m.From = new MailAddress("kennethmontealto91@gmail.com");
m.To.Add(new MailAddress("kennethmontealto91@gmail.com"));
m.Subject = "Try";
m.Body = "TEST";
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential()
{
UserName = "kennethmontealto91@gmail.com",
Password = "********"
};
smtp.EnableSsl = true;
smtp.Send(m);
推荐答案
更改您的 smtp.Host ="yourdomainname.com";
这篇关于如何使用SMTP发送邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文