[英]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.