Raised This Month: $ Target: $400
 0% 

[ANY] SMTP mail tool.


Post New Thread Reply   
 
Thread Tools Display Modes
Author
LinLinLin
Senior Member
Join Date: Sep 2021
Plugin ID:
8615
Plugin Version:
1.0.0
Plugin Category:
All
Plugin Game:
Any
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    An easy plugin make smtp mail more readability base on curl.ext
    Old 12-28-2023 , 15:43   [ANY] SMTP mail tool.
    Reply With Quote #1

    SMTP mail plugin(linux only)

    • Introduction:
      Since the method provided by curl.ext is not easy to use, i extracted the SMTP function from it and made it into a methodmap. Now it is easy to use plugin to send mail!.


    • Example:

      We now only use a SMTP handle to do the job and use a callback to get the result.
      PHP Code:
      Action Cmd_Status(int clientint args)
      {
          if( 
      client || client MaxClients || !IsClientInGame(client) || IsFakeClient(client) )
              return 
      Plugin_Handled;

          
      SMTP mail = new SMTP(smtp_hostsmtp_port);
          
      mail.SetVerify(smtp_encryptionsmtp_verifyhostsmtp_verifypeer);
          
      mail.SetSender(account_usernameaccount_password);
          
      mail.SetTitle("mail title");
          
      mail.AppendInfo("your mail info first line");
          
      mail.AppendInfo("your mail info second line");
          
      mail.AppendInfo("your mail info third line");

          
      mail.AddRecipient("[email protected]");
          
      mail.AddRecipient("[email protected]");

          
      mail.Send(MailSendResult);

          return 
      Plugin_Handled;
      }
      void MailSendResult(int code, const char[] message)
      {
          if( 
      code != SEND_SUCCESS )
          {
              
      LogError(message);
              return;
          }

          
      LogMessage(message);

    • Methodmap and Inc:
      PHP Code:
      /** Double-include prevention */
      #if defined _miuwiki_smtp_included_
        #endinput
      #endif
      #define _miuwiki_smtp_included_

      #define SEND_SUCCESS 67

      enum Encryption
      {
          
      Encryption_None,
          
      Encryption_STARTTLS,
          
      Encryption_SSL
      }

      /**
           * Init a curl to use smtp tools.
           *
           * @param  send_code      the curl code of the send result. check it's means in curl_header.
           * @param  message          message of this send, it is error on fail and a message on success.
           * 
           */
      typeset MailSendCallback 
      {
          function 
      void (int send_code, const char[] message);
      };

      methodmap SMTP Handle
      {
          
      /**
           * Init a curl to use smtp tools.
           *
           * @param  host                SMTP host
           * @param  port                  SMTP port
           * @param  timeout          Time to start a curl
           * @param  connect_timeout  Time to check a send mail is complete or not
           * @param  verbosity        Start curl debug or not.
           * 
           * @return                  A handle of the curl to use SMTP. or invalid_handle on fail.
           */
          
      public native SMTP(const char[] hostint portint timeout 30int connect_timeout 60int verbosity 0);

          
      /**
           * Set the smtp protocol and verify mode in the curl.
           *
           * @param  type            The SMTP server encryption type, usually use SSL
           * @param  verifyhost        The SMTP server need verify host? Most of time it is 2.
           * @param  verifypeer      The SMTP server need verify peer? if set to 1, need ca-bundle.crt.
           * 
           * @return                     True on success. false if something cause wrong.
           */
          
      public native bool SetVerify(Encryption typeint verifyhost 2int verifypeer 0);

          
      /**
           * Set the username and password of the sender.
           *
           * @param  username        SMTP username to login.
           * @param  password      SMTP password.
           * 
           * @return                     True on success. false if something cause wrong.
           */
          
      public native bool SetSender(const char[] username, const char[] password);

          
      /**
           * Set the mail titile, can hold 512 byte.
           *
           * @param  title     The title of the mail.
           * 
           * @return                  True on success. false if something cause wrong.
           */
          
      public native bool SetTitle(const char[] title);

          
      /**
           * Set the infomation of the mail, can hold 512 byte.
           *
           * @param  buffer     The infomation to send, always start on a new line.
           * 
           * @note           You must call SetTitle() before append your info in the mail!
           * 
           * @return                  True on success. false if something cause wrong.
           */
          
      public native bool AppendInfo(const char[] buffer);

          
      /**
           * Set recipients for emails, one email can have multiple recipients.
           *
           * @param  email     The email addres that recive the mail.
           * 
           * @note Please confirm the recipient before adding, and be careful not to fill in an empty string, 
           *       otherwise the email will not be sent
           * 
           * @return                  True on success. false if something cause wrong.
           */
          
      public native bool AddRecipient(const char[] email);

          
      /**
           * Send the mail through the curl handle.
           * 
           * @param callback The callback function of the send result.
           * 
           * @note The handle will auot delete when send complete even if it get wrong.
           *       Don't delete it after this function.
           * 
           * @return True if success, false otherwise.
          */
          
      public native bool Send(MailSendCallback callback);

    • Picture:

      Well it looks like a little concise..


      Click image for larger version

Name:	QQ图片20231229033019.png
Views:	136
Size:	58.0 KB
ID:	202685

      Recently somebody find that split pack attack is still in L4D2 server, which make it easy to attack other server and make it lagges by some invalid pack. If someone can contact valve please tell them fix that bug as soon as possible! ( 2023.12.29 - 03 : 37 : 18 )

    • Download & Note:

      !! Most of the char is limit in 512 byte. If your mail lose some character maybe that you overcome the max size of buffer.

      !! Don't delete handle after use Send(), handle delete automatically after the callback function is fired.

      !! I only test it in L4D2, but curl.ext seems can be load in all source game. So it is possible to use it in the other game.


      [Download]
      Please go to Github to get the zip.

    • Thanks:

      @raydan make the curl
      @sapphonie fork the old curl and update it
      @Peace-Maker give the example to show how to send mail

    Last edited by LinLinLin; 12-28-2023 at 17:01.
    LinLinLin is offline
    Reply



    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump


    All times are GMT -4. The time now is 07:35.


    Powered by vBulletin®
    Copyright ©2000 - 2024, vBulletin Solutions, Inc.
    Theme made by Freecode