Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace System;
- using namespace EASendMail;
- void SendMail()
- {
- SmtpMail ^oMail = gcnew SmtpMail("TryIt");
- SmtpClient ^oSmtp = gcnew SmtpClient();
- try
- {
- SmtpServer ^oServer = gcnew SmtpServer("cas.altex.ro");
- //set user authentication
- oServer->UserName = "";
- oServer->Password = "";
- //specifies the authentication mechanism.
- oSmtp->AuthType = SmtpAuthType::AuthAuto;
- //set SSL connection
- //oServer->ConnectType = SmtpConnectType::ConnectSSLAuto;
- //set smtp server port
- //oServer->Port = 465;
- //set helo domain
- //oServer->HeloDomain = "";
- oMail->From = gcnew MailAddress("" );
- oMail->To->Add( gcnew MailAddress("" ));
- oMail->Subject = "test email sent from C++/CLI";
- oMail->TextBody = "test body";
- oSmtp->SendMail( oServer, oMail );
- Console::WriteLine( "message was sent" );
- }
- catch( EASendMail::SmtpTerminatedException ^exp )
- {
- Console::WriteLine( exp->Message );
- }
- catch( EASendMail::SmtpServerException ^exp )
- {
- Console::WriteLine( "Exception: Server Respond: {0}", exp->ErrorMessage );
- }
- catch( System::Net::Sockets::SocketException ^exp )
- {
- Console::WriteLine( "Exception: Networking Error: {0} {1}", exp->ErrorCode.ToString("d"), exp->Message );
- }
- catch( System::ComponentModel::Win32Exception ^exp )
- {
- Console::WriteLine( "Exception: System Error: {0} {1}", exp->ErrorCode.ToString("d"), exp->Message );
- }
- catch( System::Exception ^exp )
- {
- Console::WriteLine( "Exception: Common: {0}", exp->Message );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement