我正在使用邮政库从我正在处理的网站上的联系页面发送电子邮件,它会发送电子邮件,但并非所有项目都包含在电子邮件中。我在代码中设置了一个断点并单步执行,所有项目都在传递的模型中,但是通过电子邮件发送的模板没有所有数据。
这是简单的模板(Contact.cshtml):
@model AccessorizeForLess.Models.ContactEmail
To: ****************@psychocoder.net
From: @Model.From
First Name: @Model.FirstName
Last Name: @Model.LastName
Subject: @Model.SelectedSubject
Message: @Model.Message
这是 ContactEmail 模型
using AccessorizeForLess.ViewModels;
using Postal;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace AccessorizeForLess.Models
{
public class ContactEmail : Email
{
public string To { get; set; }
[DataType(DataType.EmailAddress)]
[DisplayName("Email Address")]
[RegularExpression(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$", ErrorMessage = "Please enter a valid email address!")]
[Required(ErrorMessage="Please provide your email address")]
public string From { get; set; }
[DisplayName("First Name")]
[Required(ErrorMessage="Please provide your first name")]
public string FirstName { get; set; }
[DisplayName("Last Name")]
[Required(ErrorMessage="Please provide your last name")]
public string LastName { get; set; }
[DisplayName("Subject")]
[Required(ErrorMessage="Please select a subject")]
public string SelectedSubject { get; set; }
[DisplayName("Message")]
[DataType(DataType.MultilineText)]
[Required(ErrorMessage="Please provide a message for the email")]
public string Message { get; set; }
public List<EmailSubjectViewModel> Subjects { get; set; }
}
}
ContactController 中的Send方法:
public ActionResult Send(ContactEmail email)
{
ContactEmail e = new ContactEmail();
e.From = email.From;
e.FirstName = email.FirstName;
e.LastName = email.LastName;
e.SelectedSubject = email.SelectedSubject;
e.Message = email.Message;
e.Send();
return RedirectToAction("Index");
}
我已经完成了发送,传递的模型包含所有数据,但到达的电子邮件只有姓氏、主题和消息。由于某种原因,名字和电子邮件地址丢失了。