Package: coresender
Coresender Python SDKThis is the officially supported Python library forCoresender. It allows you to quickly and easily integrate with our API and improve your email deliverability.PrerequisitesPython version 3.6+The Coresender service. You can start with a free 100 emails/month developer plan and move to one of ourpricing planswhen you're done.InstallationRun the following command to get started:python3-mpipinstallcoresenderUsageHere's how to send an email using the SDK:importasyncioimportuuidimportcoresenderasyncdefmain():coresender.init(sending_account_id='<<INSERT CORESENDER SENDING ACCOUNT ID>>',sending_account_key='<<INSERT CORESENDER SENDING ACCOUNT API KEY>>',# debug=True # if True, then show some logs on stderr, or use `CORESENDER_DEBUG` environment variable)# EXAMPLE 1 – Recommendedrq=coresender.SendEmail()custom_id=str(uuid.uuid4())rq.add_to_batch(from_email='sender@example.com',from_name='sender',to_email='recipient-1@example.net',to_name='Recipient-1',reply_to_email='reply-address@example.com',reply_to_name='sender',subject='Coresender test '+custom_id,body_text='Hello,\nWorld!',body_html='<strong>Hello</strong>,<br>World!',custom_id=str(custom_id),track_opens=True,track_click=True)custom_id=str(uuid.uuid4())rq.add_to_batch(from_email='sender@example.com',from_name='sender',to_email='recipient-2@example.net',to_name='Recipient-2',subject='Coresender test '+custom_id,body_text='Hello,\nWorld!',body_html='<strong>Hello</strong>,<br>World!',custom_id=str(custom_id),track_opens=True,track_click=True)rsp=awaitrq.execute()foriinrsp:print(i)# Example 2 – For the simplest needscustom_id=str(uuid.uuid4())rsp=awaitrq.simple_email(from_email='sender@example.com',to_email='recipient-1@example.net',subject='Coresender test '+custom_id,body='<strong>Hello</strong>,<br>World!',body_type=coresender.BodyType.html)print(rsp)if__name__=='__main__':asyncio.run(main())Environment variablesInstead of putting sending account credentials directly in the code, you may want to put them in your environment variables:CORESENDER_SENDING_API_ID=<<INSERT CORESENDER SENDING ACCOUNT ID>>CORESENDER_SENDING_API_KEY=<<INSERTCORESENDERSENDINGACCOUNTAPIKEY>>The library will detect it automatically and use the credentials stored as environment variables.You can also useCORESENDER_DEBUGenvironment variable to toggle debug logs.ResponseThe result of a method call is, by default, a domain object.
Every response object hashttp_statusproperty that contains API HTTP response code. Other properties depend on the method you use.SendEmail.executeThe response is an instance ofresponses.SendEmail. Because this method allows for sending many emails with one API request, theSendEmail.all_acceptedproperty lets you quickly check if all messages were accepted. If its value isfalseit means you have to further check for rejected messages.responses.SendEmailis also an iterator that contains information about the status (and possible errors) of every message from the batch. Items are instances ofresponses.SendEmailResponse, containing data returned by the API.SendEmail.simple_emailAs this method allows for sending just one email, without batching, the response is simply an instance ofresponses.SendEmailResponse.DebuggingFor debug purposes there is a flag inCoresender.initmethod (look at Usage section above). If you enabledebug, the library will print out logs toSTDERRby default. You can configure it further by fetchingcoresenderlog handler:importlogginglogger=logging.getLogger('coresender')For more information about loggers, take a look at official documentation of theloggingmodule.DevelopmentFor installing dependencies usePipenv:pipenvinstall--dev
pipenvshellContributeThe Coresender PHP SDK is an open-source project released under MIT license. We welcome any contributions!You can help by:Writing new codeCreating issues if you find problemsHelping others with their issuesReviewing PRs