You must Sign In to post a response.
  • Category: ASP.NET

    Send email with multiple attachmants

    Hell Developers,

    I know how to send mail.But i don't how to send mail with multiple attachments And Also it will need to store on the database is important.I have tried when the text only send but attachments didn't sent.So Any of you all can help me to i am done this work.

    Then i would like to know Can i send mail with attachments by using localhost server.

    Thanking you,
    Paul.S
  • #763118

    Hello Paul Raj,

    Refer the below code :

    using System.Net;
    using System.Net.Mail;

    public void MsgBox(String ex, Page pg, Object obj) //Dynamic message box
    {
    string s = "<SCRIPT language='javascript'>alert('" + ex.Replace("\r\n", "\\n").Replace("'", "") + "'); </SCRIPT>";
    Type cstype = obj.GetType();
    ClientScriptManager cs = pg.ClientScript;
    cs.RegisterClientScriptBlock(cstype, s, s.ToString());
    }

    protected void ButtonSend_Click(object sender, EventArgs e)
    {
    TextBox Email = new TextBox();
    Email.TextMode = TextBoxMode.MultiLine;

    Email.Text += "Name : Nirav" + Environment.NewLine;
    Email.Text += "Gender : Male" + Environment.NewLine;

    MailMessage mailmesssage = new MailMessage();
    mailmesssage.From = new MailAddress("sender@gmail.com", "Paul Raj");
    mailmesssage.To.Add("receiver@gmail.com");
    mailmesssage.Subject = "Proposal Details";
    mailmesssage.Body = Email.Text;


    if (FileUpload1.HasFiles)
    {
    foreach (var file in FileUpload1.PostedFiles)
    {
    string fn = file.FileName;
    mailmesssage.Attachments.Add(new Attachment(file.InputStream, fn));
    }
    }

    //G-mail settings
    try
    {
    SmtpClient smtpClient = new SmtpClient("smtp.gmail.com");
    smtpClient.Port = 587;
    smtpClient.Credentials = new NetworkCredential("sender@gmail.com", "password");
    smtpClient.EnableSsl = true;
    smtpClient.Send(mailmesssage);
    MsgBox("We have received your request." + Environment.NewLine + "We will get back you soon.", this.Page, this);
    }
    catch (Exception ex)
    {
    Response.Write("<script>alert('" + Server.HtmlEncode(ex.Message) + "')</script>");
    }
    }

    See the attached image. It's an output i have got using above mentioned code.

    Hope this is what you are looking for.


    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #763120
    Hello Mr.Lalan ,, I got exactly output. With help of your query.Thanks for your quick reply Mr.Lalan

    Paul.S

  • #763121
    Hello Paul Raj,

    You're most welcome. If my answer satisfied your requirement you can select it as best answer. It will help us and help DNS to grow up.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763575
    mr.Lalan this is working only in
    SmtpClient smtpClient = new SmtpClient("smtp.gmail.com");
    smtpClient.Port = 587;

    i try to send mail with some other smtpclient and port name, but i got error like THE SMTP SERVER DOES NOT SUPPORT SECURE CONNECTIONS . how to i am resolve this error lalan.
    reply me

    Thankjs with
    Paul.S


Sign In to post your comments