Guest User

Untitled

a guest
Nov 16th, 2018
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. using namespace System;
  4. using namespace EASendMail;
  5.  
  6. int main(array<System::String ^> ^args)
  7. {
  8. SmtpMail ^oMail = gcnew SmtpMail("TryIt");
  9. SmtpClient ^oSmtp = gcnew SmtpClient();
  10.  
  11. // Your Gmail email address
  12. oMail->From = "gmailid@gmail.com";
  13.  
  14. // Set recipient email address, please change it to yours
  15. oMail->To = "support@emailarchitect.net";
  16.  
  17. // Set email subject
  18. oMail->Subject = "test email from Managed C++ with Gmail account";
  19.  
  20. // Set email body
  21. oMail->TextBody = "this is a test email sent from Managed C++ project with gmail";
  22.  
  23. // Gmail SMTP server address
  24. SmtpServer ^oServer = gcnew SmtpServer("smtp.gmail.com");
  25.  
  26. // If you want to use direct SSL 465 port,
  27. // please add this line, otherwise TLS will be used.
  28. // oServer->Port = 465;
  29.  
  30. // detect SSL/TLS automatically
  31. oServer->ConnectType = SmtpConnectType::ConnectSSLAuto;
  32.  
  33. // Gmail user authentication
  34. // For example: your email is "gmailid@gmail.com", then the user should be "gmailid@gmail.com"
  35. oServer->User = "gmailid@gmail.com";
  36. oServer->Password = "yourpassword";
  37.  
  38. try
  39. {
  40. Console::WriteLine("start to send email with SSL connection...");
  41. oSmtp->SendMail(oServer, oMail);
  42. Console::WriteLine("email was sent successfully!");
  43. }
  44. catch (Exception ^ep)
  45. {
  46. Console::WriteLine("failed to send email with the following error:");
  47. Console::WriteLine(ep->Message);
  48. }
  49.  
  50. return 0;
  51. }
Add Comment
Please, Sign In to add comment