如何使用SmtpClient添加图像作为附件?

时间:2013-09-18 07:57:20

标签: c# image email

我正在制作一个电子邮件客户端wpf app。它的工作正常,但我不知道如何添加图像。 我还想在PC上将我的撰写电子邮件保存为pdf或docx文件。

我搜索了很多但找不到合适的答案。 请帮忙

我的电子邮件方法如下:

 private void sendEmailB_Click(object sender, RoutedEventArgs e)
    {   SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
        client.Credentials = new NetworkCredential(gmailID.Text, gmailPass.Password);
        client.EnableSsl = true;




        MailMessage msg = new MailMessage();
        msg.From = new MailAddress(gmailID.Text);
        msg.To.Add(new MailAddress(sendEmailID.Text));
        msg.Subject = "handmail message";
        msg.Body = contentMain.Text;
        try
        {
            client.Send(msg);
            MessageBox.Show("Message sent successfully");
        }
        catch (Exception ex)
        {
            MessageBox.Show("Unable to send mail due to some reasons" + ex.Message);
        }

    }

1 个答案:

答案 0 :(得分:0)

要添加图片附件,您可以简单地试试这个

msg.Attachments.Add(new Attachment(imagePath));

其中 imagePath 包含将要上传的图像的位置(路径)。

相关问题