Я создаю свое первое веб-приложение с ядром asp. net, и я хочу, чтобы клиенты зарезервировали транспорт, но я не могу получать от них сообщения в Gmail.
Это ошибка из браузера: 1
Это моя модель просмотра:
namespace CarRental.Web.ViewModels.TransferReservation
{
using System;
using System.Collections.Generic;
using System.Text;
public class SendTransferInformationViewModel
{
public string Name { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public string NumberOfPersons { get; set; }
public string FromDestination { get; set; }
public string ToDestination { get; set; }
public string Address { get; set; }
public string Date { get; set; }
public string Time { get; set; }
public string Comment { get; set; }
}
}
Это контроллер, * для конфиденциальности:
namespace CarRental.Web.Controllers
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Threading.Tasks;
using CarRental.Web.ViewModels.TransferReservation;
using Microsoft.AspNetCore.Mvc;
using SendGrid.Helpers.Mail;
public class TransferReservation : BaseController
{
public IActionResult ChooseTransfer()
{
return this.View();
}
[HttpPost]
public IActionResult TransferReservationForm(SendTransferInformationViewModel em)
{
string name = em.Name;
string email = em.Email;
string phoneNumber = em.PhoneNumber;
string numberOfPersons = em.NumberOfPersons;
string fromDestination = em.FromDestination;
string toDestination = em.ToDestination;
string address = em.Address;
string date = em.Date;
string time = em.Time;
string comment = em.Comment;
MailMessage mm = new MailMessage();
mm.To.Add("*********imirov96@gmail.com");
mm.Subject = name;
mm.Body = phoneNumber;
mm.Body = numberOfPersons;
mm.Body = fromDestination;
mm.Body = toDestination;
mm.Body = address;
mm.Body = date;
mm.Body = time;
mm.Body = comment;
mm.From = new MailAddress(email);
mm.IsBodyHtml = false;
SmtpClient smpt = new SmtpClient("smpt.gmail.com");
smpt.Port = 587;
smpt.UseDefaultCredentials = true;
smpt.EnableSsl = true;
smpt.Credentials = new System.Net.NetworkCredential("*********mirov96@gmail.com", "********");
smpt.Send(mm);
this.ViewBag.message = "The Mail Has Been Sent To ElisCar Successfully ! We will contact you a few minutes later !";
return this.View();
}
}
}
Это вид, в котором я делаю все ярлыки для имени, телефона, даты и т. Д. c:
@using CarRental.Common
@model CarRental.Web.ViewModels.TransferReservation.SendTransferInformationViewModel
<!DOCTYPE html>
<html>
<h2 style="text-align: left;">Contact with us</h2>
<p>If you are interested in routes that are not described in the price list, other questions or to book a transfer, do not hesitate to contact us by phone <b>+359 893997896</b> or by filling out the contact form.</p>
<form asp-action="TransferReservationForm">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-row">
<div class="form-group col-md-6">
<label asp-for="Name"><b>Name:</b></label>
<input asp-for="Name" type="text" class="form-control">
</div>
<div class="form-group col-md-6">
<label asp-for="Email"><b>Email:</b></label>
<input asp-for="Email" type="email" class="form-control">
</div>
<div class="form-group col-md-6">
<label asp-for="PhoneNumber"><b>Phone Number:</b></label>
<input asp-for="PhoneNumber" type="text" class="form-control">
</div>
<div class="form-group col-md-6">
<label asp-for="NumberOfPersons"><b>Number of persons:</b></label>
<select asp-items="new List<SelectListItem>()" class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</select>
</div>
</div>
<div class="form-group">
<label asp-for="FromDestination"><b>From: Destination</b></label>
<select asp-items="new List<SelectListItem>()" class="form-control">
<option selected>Airport Varna</option>
<option>Airport Bourgas</option>
<option>Albena</option>
<option>Balchik</option>
<option>Bucuresti(Romania)</option>
<option>Bourgas</option>
<option>Bliznatsi</option>
<option>Byala</option>
<option>Costinesti(Romania)</option>
<option>Constanta(Romania)</option>
<option>Chernomorets</option>
<option>Dobrich</option>
<option>Devnya</option>
<option>Golden Sands</option>
<option>Kranevo</option>
<option>Kavarna</option>
<option>Kiten</option>
<option>Lighthouse Golf & Spa Resort</option>
<option>Mangalia(Romania)</option>
<option>Nesebar</option>
<option>Obzor</option>
<option>Plovdiv</option>
<option>Pomorie</option>
<option>Primorsko</option>
<option>Ravda</option>
<option>Ruse</option>
<option>Sv.Constantin and Elena</option>
<option>Shabla</option>
<option>Shumen</option>
<option>Sofia</option>
<option>Shkorpilovtsi</option>
<option>Sunny Beach</option>
<option>Sveti Vlas</option>
<option>Sozopol</option>
<option>Varna Center</option>
<option>Veliko Tarnovo</option>
</select>
</div>
<div class="form-group">
<label asp-for="ToDestination"><b>To: Destination</b></label>
<select asp-items="new List<SelectListItem>()" class="form-control">
<option>Airport Varna</option>
<option>Airport Bourgas</option>
<option>Albena</option>
<option>Balchik</option>
<option>Bucuresti(Romania)</option>
<option>Bourgas</option>
<option>Bliznatsi</option>
<option>Byala</option>
<option>Costinesti(Romania)</option>
<option>Constanta(Romania)</option>
<option>Chernomorets</option>
<option>Dobrich</option>
<option>Devnya</option>
<option>Golden Sands</option>
<option>Kranevo</option>
<option>Kavarna</option>
<option>Kiten</option>
<option>Lighthouse Golf & Spa Resort</option>
<option>Mangalia(Romania)</option>
<option>Nesebar</option>
<option>Obzor</option>
<option>Plovdiv</option>
<option>Pomorie</option>
<option>Primorsko</option>
<option>Ravda</option>
<option>Ruse</option>
<option>Sv.Constantin and Elena</option>
<option>Shabla</option>
<option>Shumen</option>
<option>Sofia</option>
<option>Shkorpilovtsi</option>
<option>Sunny Beach</option>
<option>Sveti Vlas</option>
<option>Sozopol</option>
<option>Varna Center</option>
<option>Veliko Tarnovo</option>
</select>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label asp-for="Address"><b>Address/Hotel/Flight Number</b></label>
<input asp-for="Address" type="text" class="form-control" placeholder="Your information about the pick up" required>
</div>
<div class="form-group col-md-4">
<label asp-for="Date"><b>Date</b></label>
<input asp-for="Date" type="date" class="form-control">
</div>
<div class="form-group col-md-2">
<label asp-for="Time"><b>Time</b></label>
<input asp-for="Time" type="time" class="form-control">
</div>
</div>
<div class="form-group">
<div class="form-group">
<label asp-for="Comment"><b>Comment:</b></label>
<textarea asp-for="Comment" type="text" class="form-control" rows="10"></textarea>
</div>
</div>
<button type="submit" class="btn btn-primary">Send</button>
<h3>@ViewBag.message</h3>
</form>
</body>
</html>