2013-04-26 2 views
0

안녕하세요, Asp.net에서 이미지 메일을 보내고 싶습니다.은 SiteMap에서 유효한 가상 경로가 아닙니다.

다음과 같은 오류가 발생했습니다 :: 'http://domain-name.com/slideshow/original/Jellyfish.png'은 (는) 유효한 가상 경로가 아닙니다.

내 코드는 다음과 같습니다

try 
    { 
     string _SenderEmailID = ReciverEmailID.Text.ToString(); 
     string _ReciverEmailID = ReciverEmailID.Text.ToString(); 
     string _Sender = FullName.Text.ToString(); 
     string post = "JellyBeans.png"; 
     string ImagePath = "http://www.domain-name.com/slideshow/original/"; 
     string iImage = ImagePath + post; 
     img1.ImageUrl = ImagePath; 

     MailMessage mail = new MailMessage(); 

     mail.To.Add(_ReciverEmailID); 
     mail.From = new MailAddress(_SenderEmailID); 

     mail.Subject = _Sender + " sent you a mail from 'www.domain-name.com"; 
     string Body = "<img alt=\"\" hspace=0 src=\"cid:imageId\" align=baseline border=0 >"; 
     AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html"); 
     LinkedResource imagelink = new LinkedResource(Server.MapPath(ImagePath)+ @post, "image/png"); 
     imagelink.ContentId = "imageId"; 
     imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64; 
     htmlView.LinkedResources.Add(imagelink); 
     mail.AlternateViews.Add(htmlView); 
     SmtpClient smtp = new SmtpClient(); 
     smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis; 
     smtp.Send(mail); 
    } 
    catch (Exception ex) 
    { 
     Response.Write(ex.Message); 
    } 

답변

2

경로는 응용 프로그램, 가상 경로에있을 때 사용되는 라인

LinkedResource imagelink = new LinkedResource(Server.MapPath(ImagePath)+ @post, "image/png"); 

Server.MapPath에서

Server.MapPath 

를 제거합니다. 이미지 URL은 직접적인 URL 또는 물리적 경로이므로 MapPath은 필요하지 않습니다.

웹 서버의 지정된 가상 경로에 해당하는 실제 파일 경로를 반환합니다.

이미지가 VisualStudio 솔루션에있는 경우 MapPath을 사용합니다.

+0

LinkedResource에서 Server.MapPath를 제거 할 때 imagelink = 새로운 LinkedResource (iImage, "image/png"); 이제 다음과 같은 새로운 오류가 발생합니다. URI 형식은 지원되지 않습니다. @ Sam Leach –

+0

웹 서버에 이미지를 넣을 수 있습니까? –

+0

예 @Sam Leach는 이미 –

관련 문제