I am trying to setup an email sending application, using a hotmail account.
The code looks like this:
MailMessage mail = new MailMessage(from, to);
mail.Subject = "Proba email";
mail.Attachments.Add(new Attachment("C:\\Documents and Settings\\Proba.txt"));
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Port = 587; // 465 568
client.Host = "smtp.live.com";
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
client.SendAsync(mail, "token");
Using, Async I actually get no errors, I even get the feedback saying message sent (Event triggers) but the message never arrives. If I use the simple client.Send void, I get the following error:
5.3.4 Requested action not taken; To continue sending messages, please sign in to your account.
So any ideas on what the problem can be? As I was trying to hand down the SMTP settings of hotmail I got various setups saying port 25, then 587 so maybe it's something there. Any help would be greatly appreciated thanks!
Here is my setup, BTW async will not return any errors.
<system.net>
<mailSettings>
<!-- E-mail server settings -->
<smtp from="[email protected]">
<network host="smtp.example.com" port="25" userName="" password="" defaultCredentials="true" />
</smtp>
</mailSettings>
void SendEmail(EmailEntity email)
{
var mailMessage = new MailMessage { From = new MailAddress(email.From) };
mailMessage.To.Add(new MailAddress(email.To));
mailMessage.Subject = email.Subject;
mailMessage.Body = email.Body;
mailMessage.IsBodyHtml = true;
// Send the email
var client = new SmtpClient();
client.Send(mailMessage);
}