Attach Files With An Email?

Nov 18, 2010

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?)

View 3 Replies


Similar Messages:

Attach Multiple Image Files To Email From Server

Nov 5, 2010

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.

View 1 Replies

Web Forms :: How To Attach Multiple Files And Send As Email Attachments

Oct 27, 2013

try {
string str = "";
HttpFileCollection fileCollection = Request.Files;
for (int i = 0; i < fileCollection.Count; i++) {
HttpPostedFile uploadfile = fileCollection[i];

[Code] ....

The control jump in catch block or showing error file could not be found, how to remove it ..

View 1 Replies

How To Attach Image With Email

Aug 31, 2010

i want to attach image with email in vb.net.

View 5 Replies

Attach DB File To Email

Mar 22, 2010

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.

View 7 Replies

Attach File To Email - Getting Error

Mar 18, 2010

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.

[Code]....

View 4 Replies

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.

View 1 Replies

Web Forms :: How To Attach File In Email Function

Apr 12, 2010

how can i store the attach file to mysql database and retrieve to let user download in eamil function.

View 1 Replies

Email - Attach And Show Image In Mail

Apr 24, 2010

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?

View 1 Replies

Web Forms :: Upload Image File And Attach To Email?

May 4, 2010

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.

View 10 Replies

Web Forms :: Extract As Excel Format Then Attach To Email

Jan 5, 2010

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.

View 3 Replies

Web Forms :: Create Word Document And Attach With Email?

Jul 3, 2010

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.

[Code]...

View 3 Replies

Controls :: Generate PDF On Button Click And Attach To Email?

May 7, 2015

i have referred to the article below:

[URL]

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.

View 1 Replies

Web Forms :: How To Attach File From Folder Using Path And Send Email

Oct 5, 2013

 i am sending mail message using smtp,,,i want to send mail message with attachments....but i do not know how to set path.

below is code :

   System.Net.Mail.Attachment attachment;    attachment = new System.Net.Mail.Attachment("how to set path here");     message.Attachments.Add(attachment);

View 1 Replies

Web Forms :: Attach PDF Document As Mail Attachment And Send Email

Jun 10, 2013

i had a requirement to attach a pdf document to mail.

i have attached the document the text is not displaying in the attachment.

here i had attached the code for reference.

string sSubject = "Automatic Email during Pinpair Activation";
string sEmail = "vidya@silkmedia.net";
string sAttach = "Silkconference_details-PDF-dial out.pdf";
string file = HttpContext.Current.Server.MapPath("~" + @"DocumentSilk Conference-Details-PDF - dial out.pdf")
byte[] bytes = System.IO.File.ReadAllBytes(file);
MemoryStream stream = new MemoryStream(bytes);
stream.Seek(0, SeekOrigin.Begin);
EmailUtils.SendEmbededImageEmailAttach(sSubject,sbEmailContent.ToString(),sEmail,sAttach,stream);

View 1 Replies

Web Forms :: Attach Files Button With No Text Box?

Nov 1, 2010

How can I remove the text box associated with a Browse button on my email page?The text box is redundant since I am attaching files (file upload) to my email message one at a time. Or, is there a standard function such as the Link (Attach a File) in Gmail that opens the user's hard drive directory?

View 2 Replies

Attach File To Email Attachment Directly From FileUpload Without Saving On Disk

Nov 5, 2012

how to add an attachement to an email from the fileupload without saving the document

to the server.

View 1 Replies

Data Controls :: How To Attach Multiple Files And Store In Database

May 21, 2013

i have a file upload control that attach files.i want to attch multiple files and that should be stored in database

and code to store multiple attchment

View 1 Replies

Does Attached Files Move With Email Or Its Link Is Sent In Email

Mar 3, 2011

I want to do file attachment funtionality with an email page. Please guide me on one thing, does attached file is send to recipient email server or it stayed on sender's mail server and its link is send ? For email if I send email from my hotmail address to gmail address will attached file be physically copied to gmail mail server or just its link (on hotmail ) will be sent and file will remain on hotmail mail server ?

View 1 Replies

AJAX :: Attach A File Using File Upload Control And Send It In Email Along With Already Attached File

Apr 27, 2016

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.

View 1 Replies

Send An Email With Aspx Files?

Sep 21, 2010

I would like to know can i send an email with aspx files.

i know that in php there is a mail() command to send emails but i couldn't find the one for aspx.

View 3 Replies

Sending .net Project Files In Email?

Sep 16, 2010

How can I send my .net project file to somebody. Which all files do I need to send?

View 7 Replies

How To Send Email With PDF And PowerPoint Slide GIF Files

Apr 8, 2012

How to send email with pdf and powerpoint slide, gif files using asp .net c#............

View 1 Replies

Transferring Files From Server Folder To Email Address

Dec 27, 2010

i am wondering if there is some abilities to send files from folder host in a server to email address. for example: i have textbox (for email address) and Button. after the user fill his email address and click the button i want to load some files from some folder in the server and to send them to the email address he provided. any idea??? (if there is any possibility to do that, please use C# + Asp.net)

View 6 Replies

VS 2008 - Sending Email Reading All ID From Excel Files

Oct 5, 2012

I want to send the email through asp.net where "To " email address list store in excel file. Send email to all email Id store in excel file. How to send the email reading all email id from excel files.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved