'unable to send an email after deployment of website using asp.net mvc 5
I am trying to send an email using asp.net MVC 5 I use the number of repositories for email it's working on local but after deployment, it's not working where I am wrong?? and Less secure app access is ON of Sender Email Id web site is : www.upgradnagpur.com (form on popup)
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Index(ContactViewModel contact)
{
if (ModelState.IsValid)
email.SendEmail(contact.Name, contact.Mobile, contact.Email, contact.Course);
return View() ;
}
this Error is after deployment
An unhandled exception occurred while processing the request.
SmtpCommandException: 5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu
5.7.14 eI_d36d7bp1NZFngrnFGXwwLoYdTokjB3-G6FBS7FlFcxcaluThbeE-YTpCODNN4GNJ8N
5.7.14 CjZxjJ5E066rJOCuVf3xYy2g-AjXr4kaoQfcSbZY2kJxiVYmLHh6-A4kclD4BtVQ>
5.7.14 Please log in via your web browser and then try again.
5.7.14 Learn more at
5.7.14 https://support.google.com/mail/answer/78754 jl18-20020a17090775d200b006f3ef214da6sm1862389ejc.12 - gsmtp
Unknown location
AuthenticationException: 534: 5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu
5.7.14 eI_d36d7bp1NZFngrnFGXwwLoYdTokjB3-G6FBS7FlFcxcaluThbeE-YTpCODNN4GNJ8N
5.7.14 CjZxjJ5E066rJOCuVf3xYy2g-AjXr4kaoQfcSbZY2kJxiVYmLHh6-A4kclD4BtVQ>
5.7.14 Please log in via your web browser and then try again.
5.7.14 Learn more at
5.7.14 https://support.google.com/mail/answer/78754 jl18-20020a17090775d200b006f3ef214da6sm1862389ejc.12 - gsmtp
MailKit.Net.Smtp.SmtpClient.AuthenticateAsync(Encoding encoding, ICredentials credentials, bool doAsync, CancellationToken cancellationToken</h2>
public void SendEmail(string Name, string Mobile, string Email, string Course)
{
var email = new MimeMessage();
email.From.Add(MailboxAddress.Parse("[email protected]"));
email.To.Add(MailboxAddress.Parse(Email));
email.Subject = "upGrad";
email.Body = new TextPart(TextFormat.Html)
{
Text = $"<div class=\"msg\"style=\"display: block; width:50%;margin-left:auto;margin-right:auto;font-size:20px;background:#f3f3f3;border-radius:5px;box-shadow:2px 2px #ddd; padding:15px; \">" +
"<div>" +
"<img style=\"height:100px; margin-left:20px;\" src=\"https://asset.brandfetch.io/idvsI-ggxm/idtgSNSCEv.png\"/>" +
"<h3 style=\"color:Black; box-shadow:2px 2px red; text-align:center;\">Student Details</h3>" +
$"<h6>Name : {Name}</h6>" +
$"<h6>Mobile : {Mobile}</h6>" +
$"<h6>Email : {Email}</h6>" +
$"<h6>Course : {Course}</h6>" +
"</div>"
};
// send email
using var smtp = new MailKit.Net.Smtp.SmtpClient();
smtp.Connect("smtp.gmail.com", 587, SecureSocketOptions.StartTls);
smtp.Authenticate("[email protected]", "hexahexa@4321");
smtp.Send(email);
smtp.Disconnect(true);
smtp.Dispose();
email.Dispose();
}
using newupgradnagpur.Repositories;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddSingleton<IEmailService, EmailService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
