当我想使用拾取目录时,mvcMailer 抱怨 SMTP 主机

发布于 2024-12-19 18:34:49 字数 2304 浏览 5 评论 0原文

这让我很紧张,因为我找不到它不起作用的理由。我有一个 mvcMailer 代码,如果我在 web.config 中指定使用 SMTP,该代码就可以工作。但我不想使用 SMTP,我想使用投递文件夹。这是执行发送的代码的一部分:

    [HttpPost]
    public ActionResult Edit(Deviation deviation, int[] Epost)
    {
        if (ModelState.IsValid)
        {
            db.Entry(deviation).State = EntityState.Modified;
            db.SaveChanges();

            if (Epost != null)
            {
                var myEpost = from p in db.Users
                              where Epost.Contains(p.UserID)
                              select p;

                myEpost.ToList();

                var subject = deviation.Benamning;
                var body = deviation.KortBeskrivning;
                var avId = deviation.DeviationId;

                foreach (var item in myEpost)
                {
                    var mailer = new UserMailer();
                    var msg = mailer.DeviationMessage(email: item.Epost, body: body, subject: subject, name: item.Name, avId: avId);
                    msg.Send();
                }
            }
            return RedirectToAction("Index");

            //return RedirectToAction("Index");
        }
        return View(deviation);
    }

如果 web.config 文件配置如下,则此代码可以工作:

<smtp from="[email protected]">
    <network enableSsl="false" host="192.168.111.11" port="25" userName="[email protected]" password="password" />
  </smtp>

但是这些替代方案都不起作用,它们都给出相同的错误(未指定 SMTP 主机):

<smtp deliveryMethod="SpecifiedPickupDirectory">
    <specifiedPickupDirectory pickupDirectoryLocation="C:\inetpub\mailroot\pickup"/>
  </smtp>

<smtp from="[email protected]" deliveryMethod="SpecifiedPickupDirectory">
    <specifiedPickupDirectory pickupDirectoryLocation="C:\inetpub\mailroot\pickup"/>
  </smtp>

我猜值得注意,尽管出现错误,但无论如何都会在放置文件夹中创建一个文件。我只是不知道出了什么问题,根据我在 mvcmailer 上找到的内容,这是正确的配置。

This has been getting on my nerves quite a bit because I can't find a reason for this not to work. I have an mvcMailer code that works if I specify in web.config to use SMTP. I don't want to use SMTP though, I want to use the drop folder. This is part of the code that does the sending:

    [HttpPost]
    public ActionResult Edit(Deviation deviation, int[] Epost)
    {
        if (ModelState.IsValid)
        {
            db.Entry(deviation).State = EntityState.Modified;
            db.SaveChanges();

            if (Epost != null)
            {
                var myEpost = from p in db.Users
                              where Epost.Contains(p.UserID)
                              select p;

                myEpost.ToList();

                var subject = deviation.Benamning;
                var body = deviation.KortBeskrivning;
                var avId = deviation.DeviationId;

                foreach (var item in myEpost)
                {
                    var mailer = new UserMailer();
                    var msg = mailer.DeviationMessage(email: item.Epost, body: body, subject: subject, name: item.Name, avId: avId);
                    msg.Send();
                }
            }
            return RedirectToAction("Index");

            //return RedirectToAction("Index");
        }
        return View(deviation);
    }

This code works if the web.config file is configured like this:

<smtp from="[email protected]">
    <network enableSsl="false" host="192.168.111.11" port="25" userName="[email protected]" password="password" />
  </smtp>

But neither of these alternatives work, they all give the same error (SMTP host not specified):

<smtp deliveryMethod="SpecifiedPickupDirectory">
    <specifiedPickupDirectory pickupDirectoryLocation="C:\inetpub\mailroot\pickup"/>
  </smtp>

<smtp from="[email protected]" deliveryMethod="SpecifiedPickupDirectory">
    <specifiedPickupDirectory pickupDirectoryLocation="C:\inetpub\mailroot\pickup"/>
  </smtp>

It's worth noting I guess, that a file is created in the drop folder anyway, despite the error. I just don't know what's wrong, based on what I've been able to find on mvcmailer this is the correct configuration to use.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

念﹏祤嫣 2024-12-26 18:34:49

尝试如下所示的方法。下面的一项总是对我有用:

  <smtp from="[email protected]" deliveryMethod="SpecifiedPickupDirectory">
          <network host="localhost" />
          <specifiedPickupDirectory pickupDirectoryLocation="c:\temp\"/>
  </smtp>

Try something like below. The below one always work for me:

  <smtp from="[email protected]" deliveryMethod="SpecifiedPickupDirectory">
          <network host="localhost" />
          <specifiedPickupDirectory pickupDirectoryLocation="c:\temp\"/>
  </smtp>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文