Click here to Skip to main content
13,145,668 members (36,839 online)
Rate this:
 
Please Sign up or sign in to 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 22-Mar-12 2:41am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

The following code might help you
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");
 
            }
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

The following code might help you
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");
 
            }
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

thaks , its work fine but i need to send mails in offline only so i can't use smtp
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 22 Mar 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100