Hello every body,
I want to send a mail with attachment of docs and pdf file only without database.
I have a form like name, email, gender(dropdown fetching),Resume Paste:textbox field and also with docs and pdf attachment. Is it possible? any body can help me
i HAVE PUTtED THE FOLLOWING CODE:
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
if (FileUpload1.PostedFile.ContentLength < 2097152) //actually it takes file size in
{
try
{
string s = FileUpload1.PostedFile.ContentLength + FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath("~\\") + "images\\" + "upload_resume\\" +s);
Attachment at = new Attachment(Server.MapPath("~\\") + "images\\" + "upload_resume\\" + s);
//mail for Company owner(eventale)
System.Web.Mail.MailMessage objMM1 = new System.Web.Mail.MailMessage();
//Dim Attachment As System.Web.Mail.MailAttachment
objMM1.To = "[email protected]";
objMM1.From = "[email protected]";
objMM1.BodyFormat = System.Web.Mail.MailFormat.Text;
objMM1.Priority = System.Web.Mail.MailPriority.High;
objMM1.Subject = "HoardingIndia";
objMM1.Body = "Dear Sir/Madam,\r\n\r\n" +
"We have received the details from hoarding buyer. \r\n\r\n" +
"Name: " + TextBox1.Text + "\r\n" +
"Marital Status: " + DropDownList1.SelectedItem.Value + "\r\n" +
"Gender: " + DropDownList2.SelectedItem.Value + "\r\n" +
"Date of Birth: " + TextBox2.Text + "\r\n" +
"Email: " + TextBox3.Text + "\r\n" +
"Phone: " + TextBox4.Text + "\r\n" +
"Current Location: " + TextBox5.Text + "\r\n" +
"Current Employer " + TextBox6.Text + "\r\n" +
"Total Experience: " + TextBox7.Text + "\r\n" +
"Position Applying for: " + TextBox8.Text + "\r\n" +
"Or Paste Resume here: " + TextBox9.Text + "\r\n";
//"Hoarding Id: " + Session["a"].ToString() + "\r\n";
objMM1.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = "smtp.gmail.com";
objMM1.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 465;
objMM1.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
objMM1.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
objMM1.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "hoardingindia2012";
objMM1.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "hoardingindia2012";
objMM1.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = true;
System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com";
//smtpmail.SmtpServer.ite
//Now, to send the message, use the Send method of the SmtpMail class
System.Web.Mail.SmtpMail.Send(objMM1);
//Response.Write("");
}
catch (Exception ex)
{
//Response.Write("");
Response.Write("Error: " + ex.Message);
}
}
else
{
Response.Write("");
}
}
}
The above code are able to send mail and details but only the thing is that it is not sending the attachment file.Please anybody can tell me how to attached the file with send mail code.
Loading

Shankar MPosted Dec 3, 2012, 4:21 AM
Yes, you can send mails with attachment with out the interaction at the database end.
To send a mail, requires the adding the namespace System.Net.Mail namespace.
To make attachment, we create an instance for the MailAttachment class.
Hope the below link might help you:
http://csharp.net-informations.com/communications/csharp-email-attachment.htm
Prabhu RajaPosted Dec 3, 2012, 4:02 AM
You can attach any kind of file types. Please refer the following article,
http://www.c-sharpcorner.com/UploadFile/ahsanshakir/sendmailwithattachment08022007001737AM/sendmailwithattachment.aspx