简体   繁体   English

ASP.NET C#-从Outlook Live SMTP服务器发送电子邮件

[英]ASP.NET C# - Sending Email from Outlook Live SMTP Server

I am struggling with attempting to send email from a .NET application. 我正努力尝试从.NET应用程序发送电子邮件。

{"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. 我使用Yahoo电子邮件地址登录我的Microsoft帐户。 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("recipeint@email.com"));


                smtpClient.Send(mail);



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

Thanks! 谢谢!

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) 请注意,某些提供商需要对您的身份验证帐户进行额外的配置才能使用其服务(例如: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 );
    }
}

i've searched something and i did not found nothing. 我已经搜索了一些东西,但没有发现任何东西。 Did you try to use yahoo smt server? 您是否尝试过使用Yahoo smt服务器?

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. 我认为这是行不通的,因为Microsoft仅使用其他电子邮件地址来创建自己的帐户,以便用户可以访问其他服务。 About email service i think that Microsoft use the other smtp server. 关于电子邮件服务,我认为Microsoft使用其他的smtp服务器。 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. 例如,如果您使用非Microsoft的电子邮件从hotmail或Outlook发送电子邮件,但是您曾经注册并创建Microsoft帐户,则我认为该程序不是使用Microsoft服务器,而是使用Yahoo服务器。

I've worked on a project that needed SMTP implemented. 我从事的项目需要实施SMTP。 The main difference is the use of DefaultCredentials. 主要区别是使用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;
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET C# - 从Gmail / Yahoo Live SMTP Server发送电子邮件不起作用 - ASP.NET C# - Sending Email from Gmail/Yahoo Live SMTP Server not working 在C#ASP.NET查询SMTP PORT中发送电子邮件 - Email sending in C# ASP.NET query SMTP PORT 使用smtp服务器,asp.net的电子邮件发送失败 - Email sending fail using smtp server, asp.net 操作已超时。 使用C#ASP.net通过smtp发送电子邮件时 - The operation has timed out. while sending email through smtp using C# ASP.net 从ASP.NET网站使用c#从默认的电子邮件客户端(例如Outlook,..)发送电子邮件 - Sending e-mail from default Email Client (ex. Outlook,.. ) using c# from an ASP.NET web site 两个Asp.Net应用程序通过SMTP从同一服务器发送电子邮件 - Two Asp.Net Applications sending email through SMTP from same server Asp.Net发送Outlook电子邮件并获取此5.7.57 SMTP客户端未通过身份验证,以在MAIL FROM期间发送匿名邮件 - Asp.Net sending outlook email and get this 5.7.57 SMTP Client was not authenticated to send anonymous mail during MAIL FROM GoDaddy 转发 email 与 SMTP 和 WebMail 在 ASP.NET ZD7EFA19FBE7D2372FD5ADB6024 - GoDaddy forwarding email with SMTP and WebMail in ASP.NET C# 使用ASP.NET MVC C#从gmail SMTP发送电子邮件 - Sending e-mail from gmail SMTP with ASP.NET MVC C# 调用Outlook电子邮件时C#asp.net超时 - c# asp.net timeout when calling a outlook email
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM