I\'ve got a simple method to send emails from the website:
... // local vars
using (var mail = new MailMessage(from, sendTo))
{
using (var smtp = new Smt
I made a tool for sending email`s with this configurations:
MailMessage mail = new MailMessage("senderaddress", "recipientaddress");
SmtpClient client = new SmtpClient()
{
Host = "smtpserver",
Port = 587,//standard port for the most of the server`s
DeliveryMethod = SmtpDeliveryMethod.Network,
EnableSsl = true,
UseDefaultCredentials = false//I got the address and the password so I don`t need the default-credentials
};
NetworkCredential na = new NetworkCredential("yoursender", "senderpassword");//I let the user input his email-address and password to get auntenthificated
client.Credentials = na;
mail.Subject = "subject";
mail.Body = "body";
mail.IsBodyHtml = true;//I use to send html formated text
try
{
client.Send(mail);
}
catch (Exception)//for debugging purposes I used the default exception
{
MessageBox.Show("Sending failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
It worked fine for me, when I wanted to send from one domain to the same host, so I hope it works also fine for you!
I think it is almost certainly a mail server configuration issue.
According to the SmptClient.Send() Documentation any incorrect configuration on your end (Host, Credentials, Port, SSL, Firewall, Anti-Virus etc) should throw an InvalidOperationException
or a SmtpException
.
The fact that you can send external mail using the same code and config - which means that you have connectivity to the mail server also very strongly suggests that the problem lies downstream.
I have worked at companies in the past that had different mail servers for internal and external mail delivery.
It could be worth considering what Credentials are being used for the message. Perhaps you have a rule which only allows members of a group (All Company or something like that) to send mail to internals addresses. You could check this by using your real domain credentials (and removing them after the test)
smtp.Credentials = new NetworkCredential("your.username", "your.password");
Either way if no exception is generated the message should have been received on the mail server, and it is up to that server to determine delivery.
Try this, it works 4 me.
MailMessage mail = new MailMessage();
mail.From = new MailAddress("mymail@mail.com");
mail.To.Add("anymail@mail.com");
mail.To.Add(empfaenger.Text);
mail.Subject = "Betreff Text";
mail.Body = "body Text";
SmtpClient client = new SmtpClient("smtp", "port");
client.UseDefaultCredentials = false;
try
{
client.Credentials = new System.Net.NetworkCredential("mymail@mail.com", "anymail@mail.com");
client.EnableSsl = true;
client.Send(mail);
}
catch (Exception ex)
{
//If not than......
}