Контроллер имеет следующий код:
Код: Выделить всё
public JsonResult SendMailToClients()
{
bool result = false;
result = SendEmail("tmasaiti@gmail.com", "attachment test ", "
Hi Flow
Whats poppin, the email you have been waiting for is finally here.
Regards
The Master
");
return Json(result, JsonRequestBehavior.AllowGet);
}
public bool SendEmail(string toEmail, string subject, string emailBody)
{
try
{
string senderEmail = System.Configuration.ConfigurationManager.AppSettings["SenderEmail"].ToString();
string senderPassword = System.Configuration.ConfigurationManager.AppSettings["SenderPassword"].ToString();
SmtpClient client = new SmtpClient("smtp.gmail.com", 587)
{
EnableSsl = true,
Timeout = 100000,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(senderEmail, senderPassword)
};
MailMessage message = new MailMessage(senderEmail, toEmail, subject, emailBody)
{
IsBodyHtml = true,
BodyEncoding = UTF8Encoding.UTF8
};
client.Send(message);
return true;
}
catch (Exception)
{
return false;
}
}
Код: Выделить всё
var SendEmail = function () {
$.ajax({
type: "Post",
url: "/Home/SendMailToClients",
success: function (data) {
if (data == true) {
alert("Message was sent successfully");
}
else
{
alert("Failure to send Message");
}
}
});
}
Код: Выделить всё
@{
ViewBag.Title = "Home Page";
}
ASP.NET
Send email now »
'System.Net.Mail.SmtpException' в System.dll
Подробнее здесь: https://stackoverflow.com/questions/602 ... il-trouble
Мобильная версия