Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
1.14/5 (4 votes)
See more:
Plz tell me How to send email with attachment in web application in C#
Posted

Any effort? This has been done so many times and internet is full of examples.

Anyway, look at this generic example to send emails:

Sending an Email in C# with or without attachments: generic routine.[^]
 
Share this answer
 
Comments
Joezer BH 11-Aug-13 4:19am    
5ed!
Manas Bhardwaj 11-Aug-13 4:21am    
thx!
ridoy 11-Aug-13 4:58am    
+5
Manas Bhardwaj 11-Aug-13 5:30am    
thx Ridoy!
Please note that there is no C# on the client side of course, so basically the question is either send mail using Javascirpt OR send mail on the server side using C#.

This is an example for C#, as requested:
C#
MailMessage mail = new MailMessage("recipient@hisDomain.com", "you@yourdomain.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
mail.Subject = "The subject.";
mail.Body = "Body text here";
client.Credentials = new NetworkCredential("account@gmail.com", "password");
client.Send(mail);


Cheers,
Edo
 
Share this answer
 
v4
Comments
Manas Bhardwaj 11-Aug-13 4:21am    
Good one +5!
ridoy 11-Aug-13 4:58am    
agree,+5
Joezer BH 11-Aug-13 5:01am    
Thank you ridoy!
Try something like..
C#
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());
}

Or, view..
A class for sending emails with attachments in C#.[^]
How-to-send-mail-with-attachment-in.html[^]
 
Share this answer
 
v3
Comments
Joezer BH 11-Aug-13 5:02am    
5ed!
ridoy 11-Aug-13 5:03am    
Thanks Maimonides,:)
Manas Bhardwaj 11-Aug-13 5:30am    
Nice +5!
ridoy 11-Aug-13 6:13am    
Thanks Manas,:)

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