Хотел настроить чтобы при оформлении заказов на почту магазина приходила емейл. Вроде как настроил все правильно, но всеравно не приходят.
В папку d:\bookshop_emails показывает что отправляются
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Mail;
namespace Domain.Concrete
{
public class EmailSettings
{
public string MailToAddress = "booookshop@mail.ru";
public string MailFromAddress = "booookshop@mail.ru";
public bool UseSsl = true;
public string Username = "booookshop@mail.ru";
public string Password = "booookshopm";
public string ServerName = "smtp.mail.ru";
public int ServerPort = 465;
public bool WriteAsFile = true;
public string FileLocation = @"d:\bookshop_emails";
}
public class EmailOrderProcessor : IOrderProcessor
{
private EmailSettings emailSettings;
public EmailOrderProcessor(EmailSettings settings)
{
emailSettings = settings;
}
public void ProcessOrder(Entities.Cart cart, Entities.ShippingDetails shippingDetails)
{
using (var smtpClient = new SmtpClient())
{
smtpClient.EnableSsl = emailSettings.UseSsl;
smtpClient.Host = emailSettings.ServerName;
smtpClient.Port = emailSettings.ServerPort;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(emailSettings.Username, emailSettings.Password);
if (emailSettings.WriteAsFile)
{
smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
smtpClient.PickupDirectoryLocation = emailSettings.FileLocation;
smtpClient.EnableSsl = false;
}
StringBuilder body = new StringBuilder()
.AppendLine("Новый заказ обработан")
.AppendLine("---")
.AppendLine("Товары:");
foreach (var line in cart.Lines)
{
var subtotal = line.Book.Price * line.Quantity;
body.AppendFormat("{0} x {1} (итого: {2:c}", line.Quantity, line.Book.Name, subtotal);
}
body.AppendFormat("Общая стоимость: {0:c}", cart.ComputeTotalValue())
.AppendLine("---")
.AppendLine("Доставка:")
.AppendLine(shippingDetails.Name)
.AppendLine(shippingDetails.Line1)
.AppendLine(shippingDetails.Line2 ?? "")
.AppendLine(shippingDetails.Line3 ?? "")
.AppendLine(shippingDetails.City)
.AppendLine(shippingDetails.Country)
.AppendLine("---")
.AppendFormat("Подарочная упаковка: {0}", shippingDetails.GiftWrap ? "Да" : "Нет");
MailMessage mailMessage = new MailMessage(
emailSettings.MailFromAddress,
emailSettings.MailToAddress,
"Новый заказ отправлен!",
body.ToString()
);
if (emailSettings.WriteAsFile)
{
mailMessage.BodyEncoding = Encoding.UTF8;
}
smtpClient.Send(mailMessage);
}
}
}
}
Можете подсказать в чем моя ошибка ?