Action Mailer MVC3和内联图像

时间:2012-05-27 07:27:35

标签: c# asp.net-mvc-3 razor actionmailer

CI正在使用MVC.ActionMailer从我的网站发送电子邮件。我在将内嵌图像嵌入电子邮件时遇到了问题。

这是我的控制器动作

public EmailResult WelcomeEmail()
    {
        WelcomeMailVM welcomeDetails = new WelcomeMailVM()
        var path = HttpContext.Current.Server.MapPath("~/Content/images/myImage.png");
        Attachments.Add("myImage.png", System.IO.File.ReadAllBytes(path));
        //Attachments.Inline["holidaymate.png"] = System.IO.File.ReadAllBytes(path);
        To.Add("someEmail@test.com");
        From = "noreply@myDomain.com";
        Subject = "Welcome to My Site;
        return Email("WelcomeEmail", welcomeDetails);
    }

以及电子邮件的视图

@model HolidayMate.API.ViewModels.Mail.WelcomeMailVM
@using ActionMailer.Net.Mvc

@{
     Layout = "~/Views/Shared/_MailLayout.cshtml";
 }
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

 <table cellpadding="0" cellspacing="0" border="0" id="backgroundTable">
 <tr>
    <td style="width:300px">
        @Html.InlineImage("myImage.png")
    </td>
    <td style="width:300px">
        <table cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td>Date</td>
                <td>@DateTime.Now.ToString("dd MMMM yyyy")
                </td>
            </tr>
        </table>
    </td>
</tr>
</table>

电子邮件发送完美。但图像不会显示在电子邮件中。我用gmail和thunderbird来解决这个问题。不幸的是,我没有测试的前景。谷歌搜索我发现以下

#38 Inline images are not displayed in Thunderbird

但我不知道在哪里发送电子邮件的内容类型。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我使用MVC Mailer而不是ActionMailer。现在图像工作正常。

但是现在我无法发送电子邮件,除非我使用以下SMTP设置,我的正常设置不起作用

<mailSettings >
  <smtp deliveryMethod="Network" from="noreply@holidaymate.co.za">
    <network enableSsl="true" host="mail.mySMTP.com" port="25"  defaultCredentials="true" />
  </smtp>
</mailSettings>

不起作用,但使用以下内容时可以正常使用

<mailSettings >
  <smtp deliveryMethod="Network" from="noreply@myDomain.co.za">
      network enableSsl="true" host="smtp.gmail.com" port="587" userName="someemail@gmail.com" password="mypassword"/>
  </smtp>
</mailSettings>
相关问题