Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using an C# ms sql server 2005 application.
Using crystal reports for the applciation.

I have to send a email of an Report which i will save as pdf file from the application.

So pls help me by telling me
1.How to send email?
2.What r the things needed for that (like what to import etc)


Thanx in advance

Regards
Nirmala Saravanan
Posted

You can use the System.Net.Mail namespace and create a new MailMessage() and also a new SmtpClient(). Then just fill in the properties on them.
 
Share this answer
 
 
Share this answer
 
C#
try
            {

                MailMessage mail = new MailMessage();

                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("userid@gmail.com");

                mail.To.Add(clientmailaddress);

                mail.Subject = "subject";

                mail.Body = "body";



                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("userid@gmail.com", "password");

                SmtpServer.EnableSsl = true;



                SmtpServer.Send(mail);

                MessageBox.Show("mail Send");

            }

            catch (Exception ex)
            {

                MessageBox.Show("mail sending fail");

            }



I think this might help you...
 
Share this answer
 
try this

MailAddress mailfrom = new MailAddress ( "frommail@gmail.com" );
MailAddress mailto = new MailAddress ( "tomail@gmail.com" );
MailMessage newmsg = new MailMessage ( mailfrom, mailto );

newmsg.Subject = "Subject of Email";
newmsg.Body = "Body(message) of email";

////For File Attachment, more file can also be attached

//Attachment att = new Attachment ( "G:\\code.txt" );
//newmsg.Attachments.Add ( att );

SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 );
smtps.UseDefaultCredentials = false;
smtps.Credentials = new NetworkCredential ( "urmail@gmail.com", "urpwd" );
smtps.EnableSsl = true;
smtps.Send ( newmsg );
 
Share this answer
 
C#
MailMessage emailmsg = new MailMessage();
        emailmsg.From = new MailAddress("abc@inc.com", "abc");
        emailmsg.To.Add(new MailAddress("cdf@inc.com", "cdf"));
        emailmsg.Subject = "Regarding Some information";
        emailmsg.Body = "stest bodcy";
        emailmsg.IsBodyHtml = true;
        emailmsg.Priority = MailPriority.Normal;
        SmtpClient mailclient = new SmtpClient("smtp.bizmail.yahoo.com");
        mailclient.Credentials = new System.Net.NetworkCredential("careers@inc.com", "123");
                
        mailclient.Send(emailmsg);
 
Share this answer
 

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