我希望有人能够帮助我,我试图将一个从一个非常好的想法发送到公司电子邮件域中的人的电子邮件,但它继续使用我的个人电子邮件。这是我的代码,也许我错过了一些东西。
namespace Mail
{
public class MailerController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(MailModel model, List<HttpPostedFileBase> attachments)
{
using (MailMessage mm = new MailMessage(model.To, model.To))
{
mm.Subject = model.Subject;
mm.Body = model.Body;
foreach (HttpPostedFileBase attachment in attachments)
{
if (attachment != null)
{
string fileName = Path.GetFileName(attachment.FileName);
mm.Attachments.Add(new Attachment(attachment.InputStream, fileName));
}
}
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
Console.WriteLine("smtp : " + smtp);
smtp.Host = "10.12.6.12";
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
Console.WriteLine("SMTP : " + smtp);
smtp.UseDefaultCredentials = true;
smtp.Port = 465;
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate,
X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtp.Send(mm);
Console.WriteLine("mm : " + mm);
ViewBag.Message = "Email has been sent.";
var emailService = new IdentityConfig.EmailService();
IdentityMessage msg = new IdentityMessage()
{
Destination = "jp.pretorius@smec.com",
Subject = "Project Document Review",
Body = "Dear Mr/Mrs/Miss, You have recieved a Document that needs to be viewed, Please Find attached document and document number for viewing, once the document has been viewed please assign it to Accepted or rejected status, thereafter please make sure you have marked the number to the project "
};
emailService.Send(msg);
}
return View("Index");
}*
答案 0 :(得分:0)
您为发件人和收件人创建MailMessage类的实例model.To
。第一个应该是发件人的电子邮件:
using (MailMessage mm = new MailMessage(model.From, model.To)) { }
另外,请查看Hans Kesting评论中的链接。