Good afternoon,
I need to send email via C #, so for testing, I wanted to know what are the credentials of outlook / hotmail to send emails
Good afternoon,
I need to send email via C #, so for testing, I wanted to know what are the credentials of outlook / hotmail to send emails
Following is a way to send emails. The login and password you use to log into your account is used as credentials.
try
{
var smtp = new SmtpClient
{
Host = "smtp_aqui",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("seu_e_mail", "sua_senha")
};
using (var smtpMessage = new MailMessage("seu_e_mail", "e_mail_destino"))
{
smtpMessage.Subject = "assunto";
smtpMessage.Body = "Corpo";
smtpMessage.IsBodyHtml = false;
smtp.Send(smtpMessage);
}
} catch (Exception ex)
{
//todo: add logging integration
//throw;
}
I use a Free service (up to a certain limit of emails, but it's high!) called SendGrid (using the SendGrid Nuget). * I'm not advertising, I just like and recommend the service, it helps me a lot. And you do not get tied to your provider's credentials, use the guys API, and you can monitor the emails sent, the ones that gave an error for delivery etc!
and the code is much simpler:
Follows:
public static async Task Send(Email email)
{
var apiKey = SendGridAPIKey;
var client = new SendGridClient(apiKey);
var from = new EmailAddress("[email protected]", "Name");
var subject = email.Subject;
var to = new EmailAddress(email.AddressTo, "User");
var plainTextContent = email.Message;
var htmlContent = email.Message;
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var response = await client.SendEmailAsync(msg);
}
Nuget Package: link
Website: link