shatafacka

Chilkat Send MAIL

Sep 18th, 2011
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. public void SendMail(string toList, string from, string bccList, string subject, string body, string pass)
  2.         {
  3.            
  4.             AppConfig.ReadSocksSettingsFromTxt();
  5.             MailForward mf = new MailForward();
  6.  
  7.  
  8.             Chilkat.MailMan mailman = new Chilkat.MailMan();
  9.             bool success;
  10.             success = mailman.UnlockComponent("MAIL12345678_***********");
  11.             if (success != true)
  12.             {
  13.                 MessageBox.Show("Component unlock failed");
  14.                 return;
  15.             }
  16.             mailman.HeloHostname = "Company-PC";
  17.             mailman.SmtpAuthMethod = "LOGIN";
  18.             //  Set the SMTP server.
  19.             mailman.SmtpHost = "smtp.company.com";
  20.             mailman.SmtpSsl = true;
  21.             mailman.StartTLS = true;
  22.             mailman.SmtpPort = 23;
  23.  
  24.             //  Set the SMTP login/password (if required)
  25.             mailman.SmtpUsername = from;                                                                            
  26.             mailman.SmtpPassword = pass;                                                      
  27.             mailman.VerboseLogging = true;
  28.  
  29.             //  Create a new email object
  30.             Chilkat.Email email = new Chilkat.Email();
  31.  
  32.  
  33.             email.Subject = subject;                                              
  34.             email.Body = body;                                                    
  35.             email.From = from;                                                    
  36.             email.AddTo("", toList);                                              
  37.  
  38.             //  Call SendEmail to connect to the SMTP server and send.
  39.             //  The connection (i.e. session) to the SMTP server remains
  40.             //  open so that subsequent SendEmail calls may use the
  41.             //  same connection.
  42.             success = mailman.SendEmail(email);
  43.             if (success != true)
  44.             {
  45.                 MessageBox.Show(mailman.LastErrorText);
  46.                 return;
  47.             }
  48.  
  49.             success = mailman.CloseSmtpConnection();
  50.             if (success != true)
  51.             {
  52.                 MessageBox.Show("Connection to SMTP server not closed cleanly.");
  53.             }
  54.         }
Advertisement
Add Comment
Please, Sign In to add comment