Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • wschwarte 44 posts 73 karma points
    Mar 30, 2016 @ 18:36
    wschwarte
    0

    Will this work with Umbraco 4.5.2 and possible to mail?

    Will this work with Umbraco 4.5.2? Or maybe an older version? And would it be possible to e-mail the generated PDF?

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Mar 31, 2016 @ 12:48
    Darren Ferguson
    0

    Hello,

    I wouldn't be sure that PDF creator would work with Umbraco 4.5 and before - because that version is very old and we don't test that far back. In theory it should, you can try installing it in trial mode.

    Emailing isn't supported out of the box - you'd need some wrapper code to do that, but it should be fairly straight forward.

    Thanks.

  • Doogie Talons 183 posts 318 karma points
    Jun 15, 2016 @ 10:51
    Doogie Talons
    0

    It is possible to mail to PDF

    1) I created a page that generates the PDF. Once you can visit the url of the page and the pdf is how you like it I call it in another page.

    What this page does is get the page as a memorstream, turnit into a file, mails it, then flushes it all once it's sent. Below is some very basic proof of concept code which achieves this.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using System.Net;
    @using System.Net.Mail;
    
    
    
    
    @if (emailedV) {
    <p>Emailed</p>      
    }
    @if (!emailedV) {
    <p>Not Emailed</p>  
    }
    
    @functions{
    
        private bool emailedV;
        private bool downloadedV;
            string pdfUrl;
        private MemoryStream pdfMemoryStream;
    
    protected override void InitializePage()
    {
    
    
    
        pdfUrl = @"http://url.com/ofthegeneratedpdf/";
                WebClient client = new WebClient();    
                try 
                {
                    pdfMemoryStream = new  MemoryStream(client.DownloadData(pdfUrl));
                } 
                finally 
                {
                    client.Dispose();
                }
    
    try
                {
    
                MailMessage mail = new MailMessage();
    
    
                mail.From = new MailAddress("from@address");
                mail.To.Add("to@address");
                mail.Subject = "Some Subject";
                mail.IsBodyHtml = false;
                mail.Body = "Body of the email text";
                mail.Attachments.Add(new System.Net.Mail.Attachment(pdfMemoryStream, "namethefile.pdf"));             
                SmtpClient smtp = new SmtpClient();
                smtp.Send(mail);
                mail.Attachments.Dispose(); 
    
                }
                catch(Exception ex)
                {
                emailedV = false;
                }  
    emailedV = true;
    }
    
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft