Mail Socket Documentation¶
mail_sockets.mail_transfer_api module¶
-
class
mail_sockets.mail_transfer_api.imap_socket(imap_server, mail_address, psswrd, debug=True)¶ Bases:
imapclient.imapclient.IMAPClientThis is a commuincation object that is used to extract data from a mail server in a form that allows it to be used as a data api.
The object is intended to serve as the ‘sister’ method to the smtp_socket() object in that it provides an api for structured data retrieval from an IMAP email server. See Documentation for more information.
Parameters: - imap_server (str) – A string that represents the domain name of the IMAP server. This will be used to initalize the IMAPClient object. eg: ‘imap.gmail.com’.
- mail_address (str) – This is the string representing the email address that the method will connect to and upload messages to eg: account@gmail.com.
- psswrd (str) – The password that will be used to sign into the IMAP server.
- debug (bool) – A boolean dictating whether the debug messages for the object print. By default it is set to True.
-
clear_forecast_data(file_name)¶ This method is intended for maintenance of the IMAP email server. It queries the IMAP server for any emails with the input client name. It then iterates over all of said emails, permanently deleting all file_name messages EXCEPT for the most recent.
Parameters: file_name (str) – A string representing the name of the file. This file_name must be concsitent with all other instances of the file in the pipeline as it must match the file_name parameter embeded in the message header.
-
debug_print(message)¶ Debug mehod that allows printing of debug messages if debug=True in initalization.
Parameters: message (str) – The string to be printed if debug=True.
-
get_forecast_data(file_name)¶ This method is intended to be used to extract client specific data from the IMAP mail server that was uploaded (by the SMTP socket) from the seven day forecast model.
Parameters: file_name (str) – A string representing the name of the file for which the most recent data is to be recieved. This file name must be concsitent with all other uses of the file name in the pipeline. Returns: payload_df – A pandas dataframe containing all the forecasting timeseries data extracted from the csv pulled from the IMAP server. Return type: pandas dataframe
-
class
mail_sockets.mail_transfer_api.smtp_socket(smtp_server, port, mail_address, psswrd, debug=True)¶ Bases:
smtplib.SMTPThis is a commuincation object that makes use of the SMTP python package to send pipeline relevant information to a SMTP server account.
This method is meant to operate similarly to the api that allows data to be sent through a network socket. It is essetally an object that wraps the smtp.SMTP object and allows relevant pipeline data to be uploaded. It is then under the assumption that this data is read from the SMTP server via the twin object imap_socket().
See documentation as to why this bootstrap method of making use of email severs was used to transfer data as opposed to traditional network sockets.
Parameters: - smtp_server (str) – A string that represents the domain name of the SMTP server. This will be used to initalize the smtplib.SMTP object. eg: ‘stmp.gmail.com’.
- port (int) – An integer representing the port number used to connect to the SMTP server.
- mail_address (str) – This is the string representing the email address that the method will connect to and upload messages to.
- psswrd (str) – The password that will be used to sign into the SMTP server.
- debug (bool) – A boolean dictating whether the debug messages for the object print. By default it is set to True.
-
debug_print(message)¶ Debug mehod that allows printing of debug messages if debug=True in initalization.
Parameters: message (str) – The string to be printed if debug=True.
-
send_forecast_data(data_path, file_name)¶ Method that sends an email with a csv attachment to the SMTP server. It is designed to send a message with the correct formatting to be read by the IMAP socket as data generated from the seven day forecast model.
It is assumed that the data parameter is a .csv file of concatinated seven day forecast data generated by the HD model. If it is not many of the tagging and formatting processes may not function. See Documentation.
Parameters: - data_path (str) – A string representing the path to the .csv file that is to be attached to the message.
- file_name (str) – This is the string that represents the path to the file that will be encoded and sent to the mail server.