我正在使用邮政图书馆从我正在处理的网站上的联系页面发送电子邮件,它会发送电子邮件,但并非所有项目都包含在电子邮件中。我设置了一个断点并逐步执行代码,所有项目都在传递的模型中,但正在通过电子邮件发送的模板没有所有数据。
这是简单的模板(Contact.cshtml):
private void makeFragmentTransaction(Fragment fragment) {
android.support.v4.app.FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.frame, fragment);
fragmentTransaction.commit();
}
这是ContactEmail模型
@model AccessorizeForLess.Models.ContactEmail
To: ****************@psychocoder.net
From: @Model.From
First Name: @Model.FirstName
Last Name: @Model.LastName
Subject: @Model.SelectedSubject
Message: @Model.Message
ContactController中的发送方法:
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; }
}
}
我已完成发送,并且传递的模型包含所有数据,但到达的电子邮件只包含姓氏,主题和消息。由于某种原因,缺少名字和电子邮件地址。
答案 0 :(得分: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>