今天使用SMTP发邮件的时候,碰到个邮箱发不了邮件的
zoho.com提供的免费企业邮箱,试了用FOXMAIL是可以发出去的。
[C#] 纯文本查看 复制代码 /// <summary>
/// 邮件发送
/// </summary>
/// <param name="from">发件人邮箱</param>
/// <param name="pwd">邮件密码</param>
/// <param name="to">收件人邮箱</param>
/// <param name="toname">收件人名字</param>
/// <param name="title">邮件主题</param>
/// <param name="body">邮件内容</param>
/// <param name="smtp">SMTP</param>
/// <param name="port">SMTP PORT</param>
/// <param name="ssl">SSL</param>
/// <param name="nickname">发件人名字</param>
/// <returns></returns>
public bool sendMail(string from, string pwd, string to, string toname, string title, string body, string smtp, int port, bool ssl, string nickname)
{
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress(from, nickname, Encoding.UTF8);
mail.To.Add(new MailAddress(to.Trim(), toname.Trim(), Encoding.UTF8));
mail.Subject = title;
mail.SubjectEncoding = Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.Normal;
mail.Body = body;
mail.BodyEncoding = Encoding.UTF8;
SmtpClient client = new SmtpClient();
client.Host = smtp;
client.Port = port;
client.EnableSsl = ssl;
client.Timeout = 60000;
client.UseDefaultCredentials = false;
//client.UseDefaultCredentials = true;
client.Credentials = new NetworkCredential(from.Split('@')[0], pwd);
//client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
client.Send(mail);
return true;
}
catch (SmtpException ex)
{
return false;
}
catch (Exception ex)
{
return false;
}
finally
{
mail.Dispose();
client = null;
}
}
catch (Exception ex)
{
return false;
}
}
发送邮件:里面的账号及密码是正确的,可以直接使用。
[C#] 纯文本查看 复制代码 sendMail("one@yswfpt.com", "azsxdcfvgb", "hyit118@yeah.net", "hy", "subject", "body", "smtp.zoho.com", 465, true, "s1");
官方的POP及SMTP说明:
Incoming Server Settings:
Incoming Server Name: pop.zoho.com
Port: 995
Require SSL: Yes
Outgoing Server Settings:
Outgoing Server Name: smtp.zoho.com
Port: 465
Require SSL: Yes
Require Authentication: Yes
现在就是发送不了,也不提示错误,提示的是超时。
FOXMAIL的设置如下(可以收发):
不知道哪个地方搞错了。代码发其它的邮箱是可以发送的。
哪位帮忙看下,谢谢了。
[attach]VS2010源文件[/attach]
|