How to set up sending and receiving email messages via Gmail account


If you wish to leave comments or ask questions, please log on or sign up.
To set up sending and receiving email messages via Gmail account, you have to enable SSL. 1C:Enterprice 8.3 provides tools for this. The article contains a simple example based on 1C:Subsystems Library 2.0 that shows you how to set up sending and receiving email messages using your Gmail account.

To set up sending and receiving email messages via Gmail account
1. Add the POP3UseSSL and SMTPUseSSL attributes of Boolean type to the EmailAccounts catalog (see Fig.1).
274625f2d2e42fb9b730a1446a916d6a.png
Fig.1. Adding the POP3UseSSL and SMTPUseSSL attributes to the configuration
2. Add the POP3UseSSL and SMTPUseSSL attributes of Boolean type to the AdditionalAccountParameters form of the EmailAccounts catalog, and then add them to the form (see Fig. 2).
bd2ade803c9ef9a616fa97e6b184c695.png
Fig.2. Adding the POP3UseSSL and SMTPUseSSL attributes to the form
3. Add the script that passes the attributes from the ItemForm to the AdditionalAccountParameters form and back:
  • Make the changes specified in Listing 1 to the ItemForm module.
  • Make the changes specified in Listing 2 and Listing 3 to the AdditionalAccountParameters form module.
4. Add the script that passes SSL flags to the connection parameters:
  • Make the changes specified in Listing 4 to the Email common module.
Procedure NotificationProcessing(EventName, Parameter, Source)
   
   If EventName = "SetAdditionalAccountParameters" And Source = Object.Ref Then
      Object.Timeout                   = Parameter.ServerTimeout;
      Object.KeepMessageCopiesAtServer = Parameter.KeepMessageCopiesAtServer;
      Object.KeepMessageAtServerPeriod = Parameter.KeepMessageAtServerPeriod;
      Object.SMTPUser                  = Parameter.SMTPUser;
      Object.SMTPPassword              = Parameter.SMTPPassword;
      Object.POP3Port                  = Parameter.POP3Port;
      Object.SMTPPort                  = Parameter.SMTPPort;
      Object.SMTPAuthentication        = Parameter.SMTPAuthentication;
      Object.SMTPAuthenticationMode    = Parameter.SMTPAuthenticationMode;
      Object.POP3AuthenticationMode    = Parameter.POP3AuthenticationMode;
      
      // Passing Use SSL flags to the object attributes
      Object.POP3UseSSL = Parameter.POP3UseSSL;
      Object.SMTPUseSSL = Parameter.SMTPUseSSL;
      // SSL

      
      Modified = True;
   EndIf;
   
EndProcedure

////////////////////////////////////////////////////////////////////////////////
// FORM COMMAND HANDLERS

&AtClient
Procedure AdditionalSettingsExecute()
   
   AccountStructure = New Structure;
   AccountStructure.Insert("Timeout",                   Object.Timeout);
   AccountStructure.Insert("KeepMessageCopiesAtServer", Object.KeepMessageCopiesAtServer);
   AccountStructure.Insert("KeepMessageAtServerPeriod", Object.KeepMessageAtServerPeriod);
   AccountStructure.Insert("SMTPUser",                  Object.SMTPUser);
   AccountStructure.Insert("SMTPPassword",              Object.SMTPPassword);
   AccountStructure.Insert("POP3Port",                  Object.POP3Port);
   AccountStructure.Insert("SMTPPort",                  Object.SMTPPort);
   AccountStructure.Insert("SMTPAuthentication",        Object.SMTPAuthentication);
   AccountStructure.Insert("SMTPAuthenticationMode",    Object.SMTPAuthenticationMode);
   AccountStructure.Insert("POP3AuthenticationMode",    Object.POP3AuthenticationMode);
   
   // Including Use SSL flags into the account structure
   AccountStructure.Insert("POP3UseSSL",              Object.POP3UseSSL);
   AccountStructure.Insert("SMTPUseSSL",              Object.SMTPUseSSL);
   // SSL
   
   CallParameters = New Structure("Ref, AccountStructure, ReadOnly", Object.Ref, AccountStructure, ReadOnly);
   
   OpenForm("Catalog.EmailAccounts.Form.AdditionalAccountParameters", CallParameters);
   
EndProcedure

Listing 1
&AtServer
Procedure OnCreateAtServer(Cancel, StandardProcessing)
   
   // Skipping the initialization to guarantee that the form will be received if the SelfTest parameter is passed.
   If Parameters.Property("SelfTest") Then
      Return;
   EndIf;
   
   Ref = Parameters.Ref;
   
   Fill_ListSMTPAuthentication();
   Fill_ListSMTPAuthenticationMode();
   
   AccountStructure = Parameters.AccountStructure;
   
   ServerTimeout = AccountStructure.Timeout;
   
   KeepMessageCopiesAtServer = AccountStructure.KeepMessageCopiesAtServer;
   KeepMessageCopiesDayCount = AccountStructure.KeepMessageAtServerPeriod;
   DeleteMessagesFromServer       = ?(KeepMessageCopiesDayCount = 0, False, True);
   
   SMTPPort = AccountStructure.SMTPPort;
   POP3Port = AccountStructure.POP3Port;
   
   // Passing Use SSL flags
   POP3UseSSL = AccountStructure.POP3UseSSL;
   SMTPUseSSL = AccountStructure.SMTPUseSSL;
   // SSL

   
   POP3AuthenticationMode = AccountStructure.POP3AuthenticationMode;
   
   SMTPAuthenticationMode = AccountStructure.SMTPAuthenticationMode;
   SMTPUser               = AccountStructure.SMTPUser;
   SMTPPassword           = AccountStructure.SMTPPassword;
   
   SMTPAuthentication = AccountStructure.SMTPAuthentication;
   
   SMTPAuthenticationSet = ?(SMTPAuthentication = Enums.SMTPAuthenticationVariants.NotDefined, False, True);
   
   Items.SMTPAuthenticationGroup.CurrentPage = ?(SMTPAuthentication = Enums.SMTPAuthenticationVariants.SetWithParameters,
                                             Items.ParametersGroup,
                                             Items.EmptyPageGroup);
   
EndProcedure

Listing 2
&AtClient
Function FillExtendedParameters()
   
   Result = New Structure;
   
   Result.Insert("SMTPPort", SMTPPort);
   Result.Insert("POP3Port", POP3Port);
   
   Result.Insert("KeepMessageCopiesAtServer", KeepMessageCopiesAtServer);
   
   If DeleteMessagesFromServer Then
      KeepMessageCopiesDayCount = KeepMessageCopiesDayCount;
   Else
      KeepMessageCopiesDayCount = 0;
   EndIf;
   
   Result.Insert("KeepMessageAtServerPeriod", KeepMessageCopiesDayCount);
   
   Result.Insert("ServerTimeout", ServerTimeout);
   
   If SMTPAuthenticationSet Then
      Result.Insert("SMTPAuthentication", SMTPAuthentication);
      If SMTPAuthentication = (SMTPAuthentication_SetWithParameters()) Then
         Result.Insert("SMTPUser", SMTPUser);
         Result.Insert("SMTPPassword", SMTPPassword);
         Result.Insert("SMTPAuthenticationMode", SMTPAuthenticationMode);
      Else
         Result.Insert("SMTPUser", "");
         Result.Insert("SMTPPassword", "");
         Result.Insert("SMTPAuthenticationMode", SMTPAuthenticationMode_None());
      EndIf;
   Else
      Result.Insert("SMTPAuthentication", SMTPAuthentication_NotDefined());
      Result.Insert("SMTPUser", "");
      Result.Insert("SMTPPassword", "");
      Result.Insert("SMTPAuthenticationMode", SMTPAuthenticationMode_None());
   EndIf;
   
   Result.Insert("POP3AuthenticationMode", POP3AuthenticationMode);
   
   // Including Use SSL flags into the result structure
   Result.Insert("POP3UseSSL", POP3UseSSL);
   Result.Insert("SMTPUseSSL", SMTPUseSSL);
   // SSL

   Return Result;
   
EndFunction

Listing 3
Function GenerateInternetProfile(Val Account,
                                    Val Password = Undefined,
                                    Val GenerateSMTPProfile = True,
                                    Val GeneratePOP3Profile = True) Export
   
   Profile = New InternetMailProfile;
   
   Profile.User = Account.User;
   
   Profile.Timeout = Account.Timeout;
   
   If ValueIsFilled(Password) Then
      Profile.Password = Password;
   Else
      Profile.Password = Account.Password;
   EndIf;
   
   If GenerateSMTPProfile Then
      Profile.SMTPServerAddress = Account.OutgoingMailServerSMTP;
      Profile.SMTPPort         = Account.SMTPPort;
      
      If Account.SMTPAuthentication = Enums.SMTPAuthenticationVariants.SimilarlyPOP3 Then
         Profile.SMTPAuthentication = SMTPAuthenticationMode.Default;
         Profile.SMTPUser           = Account.User;
         Profile.SMTPPassword       = Profile.Password;
      ElsIf Account.SMTPAuthentication = Enums.SMTPAuthenticationVariants.SetWithParameters Then
         
         If Account.SMTPAuthenticationMode = Enums.SMTPAuthenticationModes.CramMD5 Then
            Profile.SMTPAuthentication = SMTPAuthenticationMode.CramMD5;
         ElsIf Account.SMTPAuthenticationMode = Enums.SMTPAuthenticationModes.Login Then
            Profile.SMTPAuthentication = SMTPAuthenticationMode.Login;
         ElsIf Account.SMTPAuthenticationMode = Enums.SMTPAuthenticationModes.Plain Then
            Profile.SMTPAuthentication = SMTPAuthenticationMode.Plain;
         ElsIf Account.SMTPAuthenticationMode = Enums.SMTPAuthenticationModes.None Then
            Profile.SMTPAuthentication = SMTPAuthenticationMode.None;
         Else
            Profile.SMTPAuthentication = SMTPAuthenticationMode.Default;
         EndIf;
         
         Profile.SMTPUser     = Account.SMTPUser;
         Profile.SMTPPassword = Account.SMTPPassword;
         
      ElsIf Account.SMTPAuthentication = Enums.SMTPAuthenticationVariants.POP3BeforeSMTP Then
         Profile.SMTPAuthentication = SMTPAuthenticationMode.None;
         Profile.POP3BeforeSMTP = True;
      Else
         Profile.SMTPAuthentication = SMTPAuthenticationMode.None;
      EndIf;
   EndIf;
   
   If GeneratePOP3Profile Then
      Profile.POP3ServerAddress = Account.IncomingMailServerPOP3;
      Profile.POP3Port          = Account.POP3Port;
      
      If Account.POP3AuthenticationMode = Enums.POP3AuthenticationModes.APOP Then
         Profile.POP3Authentication = POP3AuthenticationMode.APOP;
      ElsIf Account.POP3AuthenticationMode = Enums.POP3AuthenticationModes.CramMD5 Then
         Profile.POP3Authentication = POP3AuthenticationMode.CramMD5;
      Else
         Profile.POP3Authentication = POP3AuthenticationMode.General;
      EndIf;
   EndIf;
   
   // Passing Use SSL flags to the profile settings
   Profile.POP3UseSSL = Account.POP3UseSSL;
   Profile.SMTPUseSSL = Account.SMTPUseSSL;
   // SSL
   
   Return Profile;
   
EndFunction

Listing 4
Now you can select the POP3 requires SSL and SMTP requires SSL check boxes when you need to send or receive email messages using your Gmail account (see Fig. 3).
0250a2dd932fd6ca445b32f986f38753.png
Fig. 3. Check boxes added by the POP3UseSSL and SMTPUseSSL
People who like this:0Yes/0No
Jan 08, 2015 01:26 AM
Hi Supporter!
Thanks you so much this document but when I practice that I could not see "GenerateInternetProfile" Listing 3 on 1C:Subsystems Library 2.0. Please help me about it.

Thanks
Link People who like this:0Yes/0No
People who like this:0Yes/0No
Jan 15, 2015 12:53 PM
Dear Huong Tram, the function "GenerateInternetProfile" is located at SubsistemsLibrary/Common/CommonModules/Email". The best way to find a missing function is Global Search available from "Edit" menu. Please, let us know if you need additional assistance.
Parent Link People who like this:0Yes/0No