【问题标题】:sending mail with dynamically created pdf as attachment in c# [closed]在c#中使用动态创建的pdf作为附件发送邮件[关闭]
【发布时间】:2014-07-02 07:14:55
【问题描述】:

我必须在我的 Web 应用程序(C#、ASP.NET)中发送带有 PDF 附件(动态创建)的电子邮件。 我们如何在 c# (Asp.net) 中使用动态创建的 pdf 作为附件发送邮件?

【问题讨论】:

标签: asp.net email pdf


【解决方案1】:

您可以像这样发送带有附件的电子邮件:

        List<string> attachments = //set a list of PDF paths here

        SmtpClient smtpClient = new SmtpClient("SmtpHost", SmtpPort);
        smtpClient.Credentials = new NetworkCredential("Username", "Password");
        smtpClient.EnableSsl = false;

        MailMessage mail = new MailMessage();
        mail.From = new MailAddress("FromEmail", "FromName", Encoding.UTF8);
        mail.To.Add(new MailAddress("ToEmail", "ToName", Encoding.UTF8));

        //get a list of your file's paths from your program and use it here
        AddAttachments(mail.Attachments, attachments);

        mail.Subject = "Subject";
        mail.SubjectEncoding = Encoding.UTF8;

        mail.IsBodyHtml = true;
        mail.Body = "Message";
        mail.BodyEncoding = Encoding.UTF8;

        //send an email
        smtpClient.Send(mail);

        //clean up
        mail.Dispose();


    void AddAttachments(AttachmentCollection attachment, List<string> attachments)
    {
        if (attachments != null)
        {
            foreach (string filePath in attachments)
                attachment.Add(new Attachment(filePath));
        }
    }

【讨论】:

    猜你喜欢
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    • 2011-12-20
    • 2017-03-09
    • 2017-07-05
    • 1970-01-01
    • 1970-01-01
    • 2014-12-30
    相关资源
    最近更新 更多