Click here to Skip to main content
11,488,212 members (75,179 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# InfoPath
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 3: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
0 Sergey Alexandrovich Kryukov 489
1 OriginalGriff 328
2 Mehdi Gholam 145
3 Sascha Lefèvre 135
4 KarstenK 115
0 Sergey Alexandrovich Kryukov 9,308
1 OriginalGriff 8,352
2 Sascha Lefèvre 3,334
3 Maciej Los 2,956
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 22 Mar 2012
Copyright © CodeProject, 1999-2015
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