-2

I am using web mail in my application configuring some credentials in the appsetting.json file. My problem is that registration mails are not arriving.enter image description here

I dont know how to solve this.

1 Answers1

0

If you use gmail, you can setup like this and sure that Turn On Access for less secure apps by https://support.google.com/accounts/answer/6010255?hl=en-GB

using System.Net;
using System.Net.Mail;

var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@example.com", "To Name");
const string fromPassword = "fromPassword";
const string subject = "Subject";
const string body = "Body";

var smtp = new SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
    Subject = subject,
    Body = body
})
{
    smtp.Send(message);
}

More reference at Sending email in .NET through Gmail

Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62
  • Its Working fine But Some Mail Id are working good and then some mail id are not working. how can i write common way and then any option are enable in mail server side. And then i am using the email Templates – Prasanth Mani Apr 01 '19 at 08:51
  • you can create config file for option at serverside and you also can save email template in xml file with mark like this Dear, {{sender}} – Hien Nguyen Apr 01 '19 at 09:38
  • What is the problem some mail as been working fine and then some mail are not working – Prasanth Mani Apr 01 '19 at 13:39