Web Forms :: How To Attach Div Content As PDF In Email
Aug 26, 2010
I need to send table information as PDF file as attachment. how do i convert Div conntent into PDF. i got many link but i was unable to convert only my Div content not HTML page. is there any way to do this.
I have an aspx page (c#) that a user can upload an image file. I'd also like them to be able to attach this image file. Is it possible to attach the image file to the email then send without saving a copy of the attchment to the web server? I don't need a copy of the file, just need to attach it.
I have this scenario where I extract the data from the database as excel format, instead of saving it some where in the drive, I want is to attach this file and send it via e-mail.
I got a following code from another thread for generating word document it seems to be working.Now I would like to know how to attach newly generated document with email.
I have several images saved as binary data in the DB. How would I remove them and attach them to an email? In the table, I have the filename, description, file(binary data), and content type.
I have a form on which anyone can send me his/her information. Now i want to add 2 or 3 file upload options so that anyone from the website can send me their files along with the information. For getting information i am using this code (in button click) which works fine for me:
using System; using System.Net.Mail; using System.Text; using System.Web.UI; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; protected void btnMyButton_Click(object sender, EventArgs e) { if (Page.IsValid) { try { string enquiry = txtEnquiry.Text.Trim(); if (String.IsNullOrEmpty(enquiry)) return; string emailTitle = GetLocaleResourceString("MyTopic.EmailTitle"); string fullName = txtFullName.Text.Trim(); string email = txtEmail.Text.Trim(); string subject = string.Format("{0}. {1}", SettingManager.StoreName, emailTitle); var body = new StringBuilder(); body.AppendFormat("<hr />{0} ({1})<hr />", emailTitle, DateTime.Now.ToShortDateString()); body.AppendFormat("<b>{0}:</b> {1}<br />", GetLocaleResourceString("MyTopic.FullName"), fullName); body.AppendFormat("<b>{0}:</b> {1}<br />", GetLocaleResourceString("MyTopic.E-MailAddress"), email); body.Append("<br />"); body.AppendFormat("<b>{0}:</b><br /> {1}<br />", GetLocaleResourceString("MyTopic.Enquiry"), MessageManager.FormatContactUsFormText(enquiry)); var from = new MailAddress(email, fullName); var emailAccount = MessageManager.DefaultEmailAccount; string body2 = body.ToString(); //required for some SMTP servers if (SettingManager.GetSettingValueBoolean("Email.UseSystemEmailForContactUsForm")) { from = new MailAddress(emailAccount.Email, emailAccount.DisplayName); body2 = string.Format("<b>From</b>: {0} - {1}<br /><br />{2}", Server.HtmlEncode(fullName), Server.HtmlEncode(email), body2); } var to = new MailAddress(emailAccount.Email, emailAccount.DisplayName); MessageManager.InsertQueuedEmail(5, from, to, string.Empty, string.Empty, subject, body2, DateTime.UtcNow, 0, null, emailAccount.EmailAccountId); pnlResult.Visible = true; pnlRequestQuote.Visible = false; }
Now I added 3 file upload options in the page, now when i try to add code in .cs file i get errors. This is what i am trying to add (in BOLD)
protected void btnMyButton_Click(object sender, EventArgs e) { if (Page.IsValid) { try { string enquiry = txtEnquiry.Text.Trim(); if (String.IsNullOrEmpty(enquiry)) return; string emailTitle = GetLocaleResourceString("MyTopic.EmailTitle"); string fullName = txtFullName.Text.Trim(); string email = txtEmail.Text.Trim(); string subject = string.Format("{0}. {1}", SettingManager.StoreName, emailTitle); var body = new StringBuilder(); body.AppendFormat("<hr />{0} ({1})<hr />", emailTitle, DateTime.Now.ToShortDateString()); body.AppendFormat("<b>{0}:</b> {1}<br />", GetLocaleResourceString("MyTopic.FullName"), fullName); body.AppendFormat("<b>{0}:</b> {1}<br />", GetLocaleResourceString("MyTopic.E-MailAddress"), email); body.Append("<br />"); body.AppendFormat("<b>{0}:</b><br /> {1}<br />", GetLocaleResourceString("MyTopic.Enquiry"), MessageManager.FormatContactUsFormText(enquiry)); //'Attach the file if (FileUpload2.HasFile) { body.Attachments.Add(new Attachment(AttachmentFile.PostedFile.InputStream, AttachmentFile.FileName)); body.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName)); body.Attachments.Add(new Attachment(FileUpload2.PostedFile.InputStream, FileUpload2.FileName)); } else { body.Attachments.Add(new Attachment(AttachmentFile.PostedFile.InputStream, AttachmentFile.FileName)); body.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName)); } var from = new MailAddress(email, fullName); var emailAccount = MessageManager.DefaultEmailAccount; string body2 = body.ToString(); //required for some SMTP servers if (SettingManager.GetSettingValueBoolean("Email.UseSystemEmailForContactUsForm")) { from = new MailAddress(emailAccount.Email, emailAccount.DisplayName); body2 = string.Format("<b>From</b>: {0} - {1}<br /><br />{2}", Server.HtmlEncode(fullName), Server.HtmlEncode(email), body2); } var to = new MailAddress(emailAccount.Email, emailAccount.DisplayName); MessageManager.InsertQueuedEmail(5, from, to, string.Empty, string.Empty, subject, body2, DateTime.UtcNow, 0, null, emailAccount.EmailAccountId); pnlResult.Visible = true; pnlRequestQuote.Visible = false; }
I get this error message:
System.Text.StringBuilder' does not contain a definition for 'Attachments' and no extension method 'Attachments' accepting a first argument of type 'System.Text.StringBuilder' could be found (are you missing a using directive or an assembly reference?)
I have the following code, everything works if i remove the attachment lines. But when i add them back i get the error below: we manage our files and content thru a content management system, so thats the reason for the links as they are with the "id=" copying the link into a browser works, but i need to attach the physical file to an email to send. If it cant be done then, we will have to just move the files into a folder outside of our management system.
I want to send email with an image attachment but the image must not be hosted on the server. I will attach the image show it in my html e-mail (with img src...). Is it possible?
I manage to upload multiple files from a web form to my local drive. Say at "D:uploadedfilesamy". How do I attach all files in the directory on my email? The email without attachment is sending just fine.
It's working good, now i need 1 more thing in this, as the pdf file generated on Button click then it should get attached automatically to mail at some email address.
I have a form in user control which submits data in database and clicking button. how to attach this button press even directly in the aspx page. I do not want to make delegate and want to use default event.
I have an asp.net panel having various controls including gridview. I have converted this panel into pdf and attached it as an email attachment using memory stream. Everything is working fine. Now I have an File upload control outside panel through which I have to attach a file and send it in mail along with the already attached panel. But I am unable to figure out how to do it.
I need to email all my Div content which include label, image, Repeater control. I have email template in Database. so i need to replace the string in template with the Div tage. so that i can send mail with required details.
I've setup my app to send an email on a button click. My code as below for when the button is clicked:
MailMessage email = new MailMessage(); email.To.Add(TextBoxTo.Text); email.Subject = TextBoxSubject.Text; email.Body = TextBoxBody.Text; SmtpClient smtp = new SmtpClient(); try { smtp.Send(email); } catch (Exception ex) { throw new Exception(ex.Message, ex); }
I'd like to be able to select some information from my database and store this in some kind of table and include this in the body of the e-mail. I know I can set the body to be html so how would I select information from my database and store in possibly a html table?
I have written a Web Page which allows Club members to send a message to Committee Members. The Input Page is a Details View which allows input of the Members name, Email Address and a text message - this is stored in a SQL Table.
Currently the Page then sends an email to Committee Members which advises that there is a message on the website. The Committee then have to log on and access the Message page to read the message.
I would like to include in the email the content of TextBoxes from the Details View.
The Code I am currently using for sending the email is below
Imports System.Net.Mail Partial Class NonAdmin_ContactUs Inherits System.Web.UI.Page Protected Sub ContactUs_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles ContactUs.ItemInserting e.Values("Date") = DateTime.Now Dim textSubject As String = "New Message" Dim textBody As String = "There is a new Message on the Malling Photographic Society Website. Please advise the rest of the Committee if you are handling this message" Dim mailMessage As New System.Net.Mail.MailMessage Dim MailClient As SmtpClient = New SmtpClient mailMessage.From = New MailAddress("jpoll@sky.com") mailMessage.To.Add(New MailAddress("committee@yahoogroups.co.uk")) mailMessage.Subject = textSubject mailMessage.Body = textBody MailClient.Send(mailMessage) End Sub End Class
I have managed to send emails with a button click to whomever i specify and whatever content i specify from my website. is there anyway i can make the email and content of the messages dynamic, and make the emails automatic?? on a date (from my database) i would like it to email a certain user some templated message: Congratulations "name", you have won "money" or something like that? Basically on a datetime, pull certain information from the database relating to the one user i am emailing, and send it automatically?