메일 이미지 첨부 보내기

작성자

카테고리:

public void Sender()
{
    MailMessage mail = new MailMessage();
    mail.To.Add("yoonhada@gmail.com");
    mail.Subject = "Test Mail";
    mail.Body = "This is for testing SMTP mail for GMAIL";
    //Attachment attachment = new Attachment("d:\\001.jpg");
    //mail.Attachments.Add(attachment);

    LinkedResource LinkedImage = new LinkedResource(@"d:\\001.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 smtpServer = new SmtpClient("smtp.gmail.com");
    smtpServer.Port = 587;
    smtpServer.Credentials = new System.Net.NetworkCredential("AAAAAAAAA@gmail.com", "AAAAAAAAAAAAA") as ICredentialsByHost;
    smtpServer.EnableSsl = true;
    ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        { return true; };
    smtpServer.Send(mail);
    Debug.Log("success");
}