Abhimanyu Singh

Abhimanyu Singh

  • NA
  • 116
  • 49.2k

How to send a mail with attachment of docs and pdf file

Dec 3 2012 3:47 AM
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("<script>alert('Posted Successfully')</script>");


                }
                catch (Exception ex)
                {
                    //Response.Write("<script>alert('Currently there is some error, Try again after some time.')</script>");
                    Response.Write("Error: " + ex.Message);
                }
            }
            else
            {
                Response.Write("<script>alert('File size exceeds maximum limit 2 MB')</script>");
            }


        }


    }

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.





Answers (2)