Click here to Skip to main content
16,018,797 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to send email with attachment in asp.net using C#,
plz help,
Posted
Comments
WmCPayne 3-Jul-17 5:29am    
Just use the code from this article, send an email with the attachment in c#.

see this..:)
C#
using System;
using System.Windows.Forms;
using System.Net.Mail;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                mail.From = new MailAddress("your_email_address@gmail.com");
                mail.To.Add("to_address");
                mail.Subject = "Test Mail - 1";
                mail.Body = "mail with attachment";

                System.Net.Mail.Attachment attachment;
                attachment = new System.Net.Mail.Attachment("your attachment file");
                mail.Attachments.Add(attachment);

                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
                MessageBox.Show("mail Send");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}


reference:

Send mail with attachment in c#[^]


A class for sending emails with attachments in C#.[^]
 
Share this answer
 
 
Share this answer
 
v2
Really?! Do you search with your query in Google[^] or CodeProject?
A simple search on CodeProject will retrieve you Tons of Result[^]
Also these will guide you...
Sending Email with attachment in ASP.NET using SMTP Server[^]
How-to-send-mail-with-attachment-in.html[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900