使用ASP.NET MVC 5在部署网站后无法发送电子邮件
我正在尝试使用ASP.NET MVC 5发送电子邮件,我使用存储库来进行电子邮件,但部署后,它在我错的地方行不通吗? 和 发件人电子邮件ID的安全应用程序访问较低 网站是: www.upgradnagpur.com (弹出窗口上的形式)
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Index(ContactViewModel contact)
{
if (ModelState.IsValid)
email.SendEmail(contact.Name, contact.Mobile, contact.Email, contact.Course);
return View() ;
}
部署后
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论