0
我正在使用Nuget包Mvc.Mailer向我的客戶發送電子郵件。我跟着this guide,我遇到了一件非常煩人的事情。我發送的電子郵件總是被髮送到垃圾郵件。這裏是我的代碼如下所示:爲什麼我的郵件在通過Mvc.Mailer發送時被標記爲垃圾郵件?
UserMailer:
public virtual MvcMailMessage Authenticatie(User user, string email)
{
ViewBag.User = user;
ViewBag.Email = email;
return Populate(x =>
{
x.Subject = "Your registration at Example";
x.ViewName = "Registration";
x.IsBodyHtml = true;
x.From = "Name <[email protected]>";
x.To.Add(email);
});
}
Registration.cshtml:
using Mvc.Mailer
<div>
<p style="display: none">Stuff in my email</p>
<h1 style="background: #e68425; text-align: center; color: white; margin: 0px; padding: 10px;">
A bunch of HTML
</h1>
<div style="background: #cf7721; text-align: center; padding: 10px;">
<h3 style="margin: 0px;"><a href="@Url.Abs(Url.Action("ALink", "Administration", new { login = @ViewBag.User.Login, h = @ViewBag.User.Activation}))">Activate account</a></h3>
</div>
<div>
<p>Dear client,</p>
<p>
Thanks for bla bla bla... And more stuff.
</p>
<table>
<tr>
<td>Login:</td>
<td>@ViewBag.User.Login</td>
</tr>
<tr>
<td>Activatiecode:</td>
<td>@ViewBag.User.Activation</td>
</tr>
</table>
</div>
Web.config文件:
<mailSettings>
<!-- Method#1: Configure smtp server credentials -->
<smtp from="Example <[email protected]@example.com>">
<network enableSsl="false" host="[email protected]" port="25" userName="[email protected]" password="xxx" />
</smtp>
</mailSettings>
我們試圖
- 通過標準的方式把我們的電子郵件,與SmtpClient。這封郵件沒有發送到垃圾郵件。
- 將x.From設置爲更好的名稱。
- 不同的內容類型
x.IsBodyHtml = true
- 發送從我們的電子郵件客戶端(同一地址)的電子郵件。這封郵件沒有發送到垃圾郵件。
問題
- 難道我們的電子郵件過度使用HTML進行過濾?
- 有沒有人遇到過這個問題,使用這個Nuget包?
- 如何阻止我的電子郵件發送垃圾郵件?
- 最重要的是:他們爲什麼要發垃圾郵件?
關於您的問題,您是否測試了多個電子郵件客戶端? (如Gmail /展望/雅虎/等)。垃圾郵件主要由ISP/Content/Personal過濾器過濾,因此您必須考慮讓您的電子郵件看起來不那麼「垃圾郵件」。你可以嘗試使用默認的UserMailer Welcome()模板,並查看它是否也發送到垃圾郵件? –
我不認爲這是原因,因爲當我發送與SmtpClient完全相同的電子郵件時,它不會發送到垃圾郵件。這意味着它不是內容,對吧?我會嘗試一些不同的客戶! –
嗯,這取決於。 SmtpClient可能只是在測試中發送純文本,而不是實際發送HTML。有很多東西可以在HTML消息中「修復」,但首先需要檢查MVCMailer Welcome()消息是否發送到垃圾郵件。從那裏你可以發現它可能是一個ISP /不可信發件人的問題。 –