Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi flokes,

please send code for automatic mail sending from infopath form . i need to avoid confromation popup window while sending mail
Posted

The following code might help you
C#
try
            {

                MailMessage mail = new MailMessage();

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

                mail.From = new MailAddress("username@mailserver.com");

                mail.To.Add("serndermailid");

                mail.Subject = "subject";

                mail.Body = "mail body";



                System.Net.Mail.Attachment attachment;

                attachment = new System.Net.Mail.Attachment("you attachment file path");

                mail.Attachments.Add(attachment);

                SmtpServer.Port = 587;

                SmtpServer.Credentials = new System.Net.NetworkCredential("username@mailserver.com", "password");

                SmtpServer.EnableSsl = true;



                SmtpServer.Send(mail);

//optional for checking
                MessageBox.Show("mail Send");

            }

            catch (Exception ex)
            {
//optional for checking
                MessageBox.Show("mail sending fail");

            }
 
Share this answer
 
The following code might help you
C#
try
            {

                MailMessage mail = new MailMessage();

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

                mail.From = new MailAddress("username@mailserver.com");

                mail.To.Add("sendermailid");

                mail.Subject = "subject";

                mail.Body = "mail body";



                System.Net.Mail.Attachment attachment;

                attachment = new System.Net.Mail.Attachment("you attachment file path");

                mail.Attachments.Add(attachment);

                SmtpServer.Port = 587;

                SmtpServer.Credentials = new System.Net.NetworkCredential("username@mailserver.com", "password");

                SmtpServer.EnableSsl = true;



                SmtpServer.Send(mail);

//optional for checking
                MessageBox.Show("mail Send");

            }

            catch (Exception ex)
            {
//optional for checking
                MessageBox.Show("mail sending fail");

            }
 
Share this answer
 
thaks , its work fine but i need to send mails in offline only so i can't use smtp
 
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