McvMailer没有看到美景 [英] McvMailer doesn't see views

查看:150
本文介绍了McvMailer没有看到美景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中使用MvcMailer。我创建了一个名为MyMailer一个新的类库项目。现在,我想在我的MVC应用程序来使用它。

I want to use MvcMailer in my application. I created a new class library project called MyMailer. Now I want to use it in my MVC app.

// mailer    
public class MyMailer : MailerBase, IEdoctorMailer  
{
    public MyMailer()
    {
        MasterName = "_Layout";
    }

    public virtual MvcMailMessage Invitation()
    {
        //ViewBag.Data = someObject;
        var msg = Populate(x =>
        {
            x.Subject = Labels.Invitation;
        x.ViewName = "Invitation";
        x.From = new MailAddress("xxx@gmail.com");
        x.To.Add("yyy@gmail.com");
        });

        return msg;
    }
}

//mvc controller
IMyMailer mailer = new MyMailer();
var inv = mailer.Invitation();
inv.Send(new DefaultSmtpClient()); // see below

public class DefaultSmtpClient : SmtpClient, ISmtpClient
{
    public DefaultSmtpClient() : base("smtp.gmail.com", 587)
    {
        EnableSsl = true;
        UseDefaultCredentials = false;
        Credentials = new NetworkCredential("login", "pass");         
    }

    public void SendAsync(MailMessage mailMessage)
    {
        throw new NotImplementedException();
    }
}

在MyMailer项目查看/ MyMailer / Invitation.cshtml 有一个在它的一些文本的文件。

In MyMailer project in Views/MyMailer/Invitation.cshtml there is a file with some text in it.

当我发送电子邮件,它实际上到达。但这种观点的邀请不包括(有没有身体的话)。我想这是因为发送方法,形式MVC项目执行,但是这只是我的猜测。

When I send the email it actually arrives. But this Invitation view is not included (there's no body at all). I assume it's because the Send method is executed form the mvc project, but that's just my guess.

我甚至把一个断点查看/ MyMailer / _Layut.cshtml - > RenderBody(),但它从来没有踏进了。

I even put a breakpoint in Views/MyMailer/_Layut.cshtml --> RenderBody(), but it never stepped into it.

我应该怎么做,包括有何看法?

What should I do to include the view?

推荐答案

既然你MvcMailer视图是一个类库,你必须告诉MVC项目在哪里以及如何通过重写的ViewEngine或的VirtualPathProvider找到他们

Since you're MvcMailer views are in a class library, you'll have to tell the MVC project where and how to find them by overriding the ViewEngine or VirtualPathProvider.

这篇关于McvMailer没有看到美景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆