将图像包含到 MvCMailer Mail 时路径应该如何

发布于 2024-12-22 14:54:53 字数 1420 浏览 5 评论 0原文

我试图在使用 MvCMailer 发送电子邮件时嵌入图像,如下所示:

    Dictionary<string,string> resources = new Dictionary<string,string>();
    resources["logo"] = new Uri(new Uri(string.Format("{0}://{1}{2}", System.Web.HttpContext.Current.Request.Url.Scheme, System.Web.HttpContext.Current.Request.Url.Authority, Url.Content("~"))), "/Content/images/logo.png").ToString();
    mailSender.Confirm(user.Username, user.Email, link,resources).Send();

它是如何生成的:

URI formats are not supported.

我不确定我应该发送什么样的路径,以及如何生成它?

堆栈跟踪:

     at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.Net.Mail.AttachmentBase.SetContentFromFile(String fileName, ContentType contentType)
   at Mvc.Mailer.LinkedResourceProvider.Get(String contentId, String filePath)

im trying to embed an image when sending an email with MvCMailer like this:

    Dictionary<string,string> resources = new Dictionary<string,string>();
    resources["logo"] = new Uri(new Uri(string.Format("{0}://{1}{2}", System.Web.HttpContext.Current.Request.Url.Scheme, System.Web.HttpContext.Current.Request.Url.Authority, Url.Content("~"))), "/Content/images/logo.png").ToString();
    mailSender.Confirm(user.Username, user.Email, link,resources).Send();

How ever it generate this:

URI formats are not supported.

Im not sure what kind of path i should send, and how to generate it ?

Stack Trace:

     at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.Net.Mail.AttachmentBase.SetContentFromFile(String fileName, ContentType contentType)
   at Mvc.Mailer.LinkedResourceProvider.Get(String contentId, String filePath)

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

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

发布评论

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

评论(2

救赎№ 2024-12-29 14:54:53

资源路径应该是磁盘上的本地路径,而不是 URL。

resources["logo"] = Server.MapPath("~/Content/images/logo.png");

Resource paths should be local paths on disk, not URLs.

Write

resources["logo"] = Server.MapPath("~/Content/images/logo.png");
新人笑 2024-12-29 14:54:53

您必须添加代码才能添加附件。
如果这不是权利或权限问题,请尝试此操作

public virtual MailMessage Welcome(string email, string name)
{     
   var mailMessage = new MailMessage{Subject = "Welcome to MvcMailer"};
   mailMessage.To.Add(email);
   ViewBag.Name = name;
   PopulateBody(mailMessage, viewName: "Welcome");
   return mailMessage; 
} 

You will have to add the code to do the attachment..
if this is not a rights or permissions issue try this

public virtual MailMessage Welcome(string email, string name)
{     
   var mailMessage = new MailMessage{Subject = "Welcome to MvcMailer"};
   mailMessage.To.Add(email);
   ViewBag.Name = name;
   PopulateBody(mailMessage, viewName: "Welcome");
   return mailMessage; 
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文