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)
4

2 に答える 2

4

リソースパスは、URLではなくディスク上のローカルパスである必要があります。

書く

resources["logo"] = Server.MapPath("~/Content/images/logo.png");
于 2011-12-21T19:22:52.507 に答える
-1

添付ファイルを作成するには、コードを追加する必要があります。これが権利または権限の問題でない場合は、これを試してください。

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; 
} 
于 2011-12-21T19:21:42.670 に答える