0

我正在使用邮政库从我正在处理的网站上的联系页面发送电子邮件,它会发送电子邮件,但并非所有项目都包含在电子邮件中。我在代码中设置了一个断点并单步执行,所有项目都在传递的模型中,但是通过电子邮件发送的模板没有所有数据。

这是简单的模板(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");
}

我已经完成了发送,传递的模型包含所有数据,但到达的电子邮件只有姓氏、主题和消息。由于某种原因,名字和电子邮件地址丢失了。

4

1 回答 1

0

我将Contact.cshtml(我的电子邮件模板)更改为如下所示,现在所有内容都已填充

 Content-Type: text/html; charset=utf-8  
@model AccessorizeForLess.Models.ContactEmail
To: **************@psychocoder.net
From: @Model.From


<html>
    <head>
        <title>Email from @Model.From</title>
        <style>
            hr
            {
               border: 1px solid #e50e8d;
               box-shadow: 5px 5px 5px #888888;
            }
        </style>
    </head>
<body>
    <p>Dear Admin, you have received an email from @Model.FirstName  @Model.LastName regarding @Model.SelectedSubject .</p>
    <p>The content of the message is below:<br />
    <hr />
    Message: @Model.Message<br />
    <hr /></p>
</body>
</html>
于 2015-08-01T03:08:34.783 回答