1

I want to send transactional and marketing emails using 'SendInBlue'. I also want to use Python language to do the same. I have visited the API doc of SendInBlue and followed the same procedure, still unsuccessful in sending the emails.

from mailin import Mailin
    m = Mailin("https://api.sendinblue.com/v2.0","ScrWGqd296ya0CWq")
    data = { "to" : {"aman@gmail.com":"to whom!"},
        "from" : ["amandeep@gmail.com", "from email!"],
        "subject" : "Subject...",
        "html" : "This is the <h1>HTML</h1>",
        "attachment" : ["https://example.com/path-to-file/filename1.pdf", "https://example.com/path-to-file/filename2.jpg"]
    }

    result = m.send_email(data)
    print(result)

I have also downloaded mailin-api-python from github and ran this script. I don't have any idea where to setup to my smtp details.

**I have changed the API key just for security purpose.

Grokify
  • 15,092
  • 6
  • 60
  • 81

1 Answers1

1

I would strongly recommend you to use the latest version of SendinBlue's Python wrapper where they have provided an example

from __future__ import print_function
import time
import sib_api_v3_sdk
from sib_api_v3_sdk.rest import ApiException
from pprint import pprint

# Configure API key authorization: api-key
configuration = sib_api_v3_sdk.Configuration()
configuration.api_key['api-key'] = 'API-KEY'

# create an instance of the API class
api_instance = sib_api_v3_sdk.SMTPApi(sib_api_v3_sdk.ApiClient(configuration))
senderSmtp = sib_api_v3_sdk.SendSmtpEmailSender(name="test",email="youremail@gmail.com")
sendTo = sib_api_v3_sdk.SendSmtpEmailTo(email="recipientEmail@gmail.com",name="Recipient Name")
arrTo = [sendTo] #Adding `to` in a list
send_smtp_email = sib_api_v3_sdk.SendSmtpEmail(sender=senderSmtp,to=arrTo,html_content="This is a test",subject="This is a test subject") # SendSmtpEmail | Values to send a transactional email

try:
    # Send a transactional email
    api_response = api_instance.send_transac_email(send_smtp_email)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling SMTPApi->send_transac_email: %s\n" % e)

I got a sample script working:

I successfully received the email and the messageId as the response.

Please let me know if it helps!

rudy0807
  • 152
  • 1
  • 8
  • 1
    in the recent version, the class name `SMTPApi` has changed to `TransactionalEmailsApi`, check [the issue](https://github.com/sendinblue/APIv3-python-library/issues/58#issuecomment-725522667) – Abdulkader Khateeb Sep 19 '21 at 15:26