Advertisement
Guest User

Untitled

a guest
Mar 9th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. using namespace System;
  2. using namespace EASendMail;
  3. void SendMail()
  4. {
  5. SmtpMail ^oMail = gcnew SmtpMail("TryIt");
  6. SmtpClient ^oSmtp = gcnew SmtpClient();
  7.  
  8. try
  9. {
  10. SmtpServer ^oServer = gcnew SmtpServer("cas.altex.ro");
  11.  
  12. //set user authentication
  13. oServer->UserName = "";
  14. oServer->Password = "";
  15.  
  16. //specifies the authentication mechanism.
  17. oSmtp->AuthType = SmtpAuthType::AuthAuto;
  18.  
  19. //set SSL connection
  20. //oServer->ConnectType = SmtpConnectType::ConnectSSLAuto;
  21.  
  22. //set smtp server port
  23. //oServer->Port = 465;
  24.  
  25. //set helo domain
  26. //oServer->HeloDomain = "";
  27.  
  28. oMail->From = gcnew MailAddress("" );
  29. oMail->To->Add( gcnew MailAddress("" ));
  30. oMail->Subject = "test email sent from C++/CLI";
  31. oMail->TextBody = "test body";
  32.  
  33. oSmtp->SendMail( oServer, oMail );
  34. Console::WriteLine( "message was sent" );
  35. }
  36. catch( EASendMail::SmtpTerminatedException ^exp )
  37. {
  38. Console::WriteLine( exp->Message );
  39. }
  40. catch( EASendMail::SmtpServerException ^exp )
  41. {
  42. Console::WriteLine( "Exception: Server Respond: {0}", exp->ErrorMessage );
  43. }
  44. catch( System::Net::Sockets::SocketException ^exp )
  45. {
  46. Console::WriteLine( "Exception: Networking Error: {0} {1}", exp->ErrorCode.ToString("d"), exp->Message );
  47. }
  48. catch( System::ComponentModel::Win32Exception ^exp )
  49. {
  50. Console::WriteLine( "Exception: System Error: {0} {1}", exp->ErrorCode.ToString("d"), exp->Message );
  51. }
  52. catch( System::Exception ^exp )
  53. {
  54. Console::WriteLine( "Exception: Common: {0}", exp->Message );
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement