我正在使用以下基本代码:
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.to.add("someone@hotmail.com");
msg.to.add("someone@gmail.com");
msg.to.add("someone@myDomain.com");
msg.From = new MailAddress("me@myDomain.com", "myDomain", System.Text.Encoding.UTF8);
msg.Subject = "subject";
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = "body";
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = false;
//Add the Creddentials
SmtpClient client = new SmtpClient();
client.Host = "192.168.0.24";
client.Credentials = new System.Net.NetworkCredential("me@myDomain.com", "password");
client.Port = 25;
try
{
client.Send(msg);
}
catch (System.Net.Mail.SmtpException ex)
{
sw.WriteLine(string.Format("ERROR MAIL: {0}. Inner exception: {1}", ex.Message, ex.InnerException.Message));
}
问题是邮件只发送到我域中的地址(someone@mydomain.com),我得到以下2个地址的以下异常:
System.Net.Mail.SmtpFailedRecipientException:邮箱不可用。服务器响应是:此位置没有此类域
我怀疑它与阻止我的smtp客户端的东西有关,但不知道如何处理这个问题。 任何的想法?谢谢!
答案 0 :(得分:4)
Ron是正确的,只需使用587端口,它就可以正常工作。
检查此代码并查看其是否有效:
using System;
using System.Windows.Forms;
using System.Net.Mail;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("your_email_address@gmail.com");
mail.To.Add("to_address@mfc.ae");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("mail Send");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
答案 1 :(得分:2)
尝试使用port = 587。这是有用的相关链接:http://mostlygeek.com/tech/smtp-on-port-587/comment-page-1/