Mail보낼때 이미지 삽입하기

iamgun(46)
Published in
#it
Words
70
Reading
1 min
9y
Listen to this post
~1 min
MailMessage Mail = new MailMessage();        
 
        Mail.From = new MailAddress("[email protected]");
        Mail.To.Add("[email protected]");
        Mail.Subject = "This is Image Test.";
        Mail.Body = "This is the body of the email";
        LinkedResource LinkedImage = new LinkedResource(@"J:\My Documents\Advika1.jpg");
        LinkedImage.ContentId = "MyPic";
        AlternateView htmlView = AlternateView.CreateAlternateViewFromString("You should see image next to this line. <img src=cid:MyPic>", null, "text/html");
 
        htmlView.LinkedResources.Add(LinkedImage);
        Mail.AlternateViews.Add(htmlView);
        SmtpClient smtp = new SmtpClient("111.111.111.111", 25); 
        try
        {
            smtp.Send(Mail);
        }
        catch (SmtpException ex)
        {
            throw ex;
        }