2
votes

I am struggling with attempting to send email from a .NET application.

{"Mailbox unavailable. The server response was: 5.7.3 Requested action aborted; user not authenticated"}    System.Exception {System.Net.Mail.SmtpException}

Now this would seem to indicate (from my limited understanding at least) that there is something wrong with my credentials, that is, my email address and password.

Here is the problem. I login into my Microsoft account using a Yahoo email address. This is the address I supplied as part of the credentials. If this is not correct, where can I find the appropriate email address, or what else might I be missing?

  try
            {
                SmtpClient smtpClient = new SmtpClient("smtp-mail.outlook.com", 587);

                smtpClient.EnableSsl = true;
                smtpClient.Credentials = new System.Net.NetworkCredential("kelly*******@yahoo.com", "myMicrosoftPassword");
                smtpClient.UseDefaultCredentials = true;
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

                MailMessage mail = new MailMessage();

                //Setting From , To and CC
                mail.From = new MailAddress("kelly*******@yahoo.com", "Kelly");
                mail.To.Add(new MailAddress("[email protected]"));


                smtpClient.Send(mail);



            } 
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }

Thanks!

3

3 Answers

0
votes

Try using this as skeleton to send a mail: Please note the certificate part. Please note that some providers need extra configuration to be done on your authentication account to use their services (eg: Google)

using( var mail = new System.Net.Mail.MailMessage() )
{
    mail.From = new System.Net.Mail.MailAddress( fromAddress );
    mail.Subject = subject;
    mail.Body = body;               

    foreach( var attachment in attachments )
       mail.Attachments.Add( new Attachment( attachment ) );

    foreach( var address in toAddresses )
       mail.To.Add( address );

    using( var smtp = new System.Net.Mail.SmtpClient( smtpAddress, smtpPort ) )
    {
        smtp.EnableSsl = enableSsl;
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
        smtp.UseDefaultCredentials = false;
        smtp.Credentials = new NetworkCredential( authUserName, authPassword );

        ServicePointManager.ServerCertificateValidationCallback =
        ( sender, certificate, chain, sslPolicyErrors ) => true;

        smtp.Send( mail );
    }
}
0
votes

i've searched something and i did not found nothing. Did you try to use yahoo smt server?

smtp.mail.yahoo.com

I think that it doesn't work becouse Microsoft use the other email addresses only to create own accounts wich users can access to the othere service. About email service i think that Microsoft use the other smtp server. For example if you send an email from hotmail or outlook using a email that isn't of Microsoft but you used to sign up and to create a Microsoft account I think that the program doesn't use Microsoft server but the yahoo ones.

0
votes

I've worked on a project that needed SMTP implemented. The main difference is the use of DefaultCredentials. Try change it and see if it works. If you already tried that maybe try with another email account, the problem could also be there. Here's how I did it:

 public void SendEmail(string recipient, string subject, string text)
    {
        //The smtp and port can be adjusted, deppending on the sender account
        SmtpClient client = new SmtpClient(_smtpHostServer);
        client.Port = _smtpHostPort;
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;

        try
        {
            System.Net.NetworkCredential credentials =
                new System.Net.NetworkCredential(_serveraddress, _serverpassword);
            client.EnableSsl = true;
            client.Credentials = credentials;
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        //Creates a new message
        try {
            var mail = new MailMessage(_serveraddress.Trim(), recipient.Trim());
            mail.Subject = subject;
            mail.Body = text;

            client.Send(mail);
        }
        //Failing to deliver the message or to authentication will throw an exception
        catch (Exception ex){
            Console.WriteLine(ex.Message);
            throw;
        }
    }