C# 将图像包含到MvCMailer邮件中时的路径

C# 将图像包含到MvCMailer邮件中时的路径,c#,asp.net-mvc,asp.net-mvc-3,mvcmailer,C#,Asp.net Mvc,Asp.net Mvc 3,Mvcmailer,我尝试在使用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.We

我尝试在使用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();
我不知道我应该发送什么样的路径,以及如何生成它

堆栈跟踪:

     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)

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

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; 
} 

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

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; 
} 

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

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

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

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

当您发送附件时。。这是从本地计算机发出的,为什么不让MVCMailer使用附件的相对路径。您使用的是System.Net.Mail,因此文件共享的权限/权限问题之外的问题看起来像。。。发送附件时,还需要创建附件对象。。这是从本地计算机发出的,为什么不让MVCMailer使用附件的相对路径。您使用的是System.Net.Mail,因此文件共享的权限/权限问题之外的问题看起来像。。。您还需要创建一个附件对象。但是我想知道如何将其作为背景图像而不是内联图像?使用CSS,带有
cid:
URI。很抱歉,我没有完全理解cid:URI是什么。您能给我一个小例子吗?
background image:url('cid:logo'))
请注意,并非所有邮件客户端都支持背景图像。但我想知道如何将其作为背景图像而不是内联图像?使用CSS,使用
cid:
URI。很抱歉,我没有完全理解cid:URI是什么。你能给我一个小例子吗?
背景图像:url('cid:logo'))
请注意,并非所有邮件客户端都支持背景图像。我知道他告诉他必须添加代码才能嵌入图像。。我们在我当前的项目中不使用MCVMailer..我知道他告诉他他必须添加代码来嵌入图像。。我们在我当前的项目中不使用MCVMailer。。