import sendgrid
import os


sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))

data = {
    "content": [
        {
            "type": "text/html",
            "value": "<html><p>Hello, world!</p><img src=[CID GOES HERE]></img></html>"
        }
    ],
    "from": {
        "email": "sam.smith@example.com",
        "name": "Sam Smith"
    },
    "headers": {},
    "mail_settings": {
        "footer": {
            "enable": True,
            "html": "<p>Thanks</br>The SendGrid Team</p>",
            "text": "Thanks,/n The SendGrid Team"
        },
    },
    "reply_to": {
        "email": "sam.smith@example.com",
        "name": "Sam Smith"
    },
    "send_at": 1409348513,
    "subject": "Hello, World!",
    "template_id": "[YOUR TEMPLATE ID GOES HERE]",
    "tracking_settings": {
        "subscription_tracking": {
            "enable": True,
            "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",
            "substitution_tag": "<%click here%>",
            "text": "If you would like to unsubscribe and stop receiving these emails <% click here %>."
        }
    }
}

response = sg.client.mail.send.post(request_body=data)

import sendgrid
import os
from flask import request, Flask

app = Flask(__name__)


@app.route("/sendgrid")
def send():
    sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))

    data = {
        "content": [
            {
                "type": "text/html",
                "value": "<html>{}</html>".format(request.args["html_content"])
            }
        ],
        "from": {
            "email": "sam.smith@example.com",
            "name": "Sam Smith"
        },
        "headers": {},
        "mail_settings": {
            "footer": {
                "enable": True,
                "html": "<html>{}</html>".format(request.args["html_footer"]),
                "text": "Thanks,/n The SendGrid Team"
            },
        },
        "reply_to": {
            "email": "sam.smith@example.com",
            "name": "Sam Smith"
        },
        "send_at": 1409348513,
        "subject": "Hello, World!",
        "template_id": "[YOUR TEMPLATE ID GOES HERE]",
        "tracking_settings": {
            "subscription_tracking": {
                "enable": True,
                "html": "<html>{}</html>".format(request.args["html_tracking"]),
                "substitution_tag": "<%click here%>",
                "text": "If you would like to unsubscribe and stop receiving these emails <% click here %>."
            }
        }
    }

    response = sg.client.mail.send.post(request_body=data)

Add RFS to `sendgrid` test
Add RFS to `sendgrid` test

  import sendgrid
  import os
+ from flask import request, Flask
+ 
+ app = Flask(__name__)
  
  
+ @app.route("/sendgrid")
+ def send():
- sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
+     sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
  
- data = {
+     data = {
-     "content": [
+         "content": [
-         {
+             {
-             "type": "text/html",
+                 "type": "text/html",
-             "value": "<html><p>Hello, world!</p><img src=[CID GOES HERE]></img></html>"
+                 "value": "<html>{}</html>".format(request.args["html_content"])
+             }
-         }
+         ],
-     ],
-     "from": {
+         "from": {
-         "email": "sam.smith@example.com",
+             "email": "sam.smith@example.com",
-         "name": "Sam Smith"
+             "name": "Sam Smith"
-     },
-     "headers": {},
-     "mail_settings": {
-         "footer": {
-             "enable": True,
-             "html": "<p>Thanks</br>The SendGrid Team</p>",
-             "text": "Thanks,/n The SendGrid Team"
          },
+         "headers": {},
+         "mail_settings": {
+             "footer": {
+                 "enable": True,
+                 "html": "<html>{}</html>".format(request.args["html_footer"]),
+                 "text": "Thanks,/n The SendGrid Team"
+             },
-     },
+         },
-     "reply_to": {
+         "reply_to": {
-         "email": "sam.smith@example.com",
+             "email": "sam.smith@example.com",
-         "name": "Sam Smith"
+             "name": "Sam Smith"
-     },
+         },
-     "send_at": 1409348513,
+         "send_at": 1409348513,
-     "subject": "Hello, World!",
+         "subject": "Hello, World!",
-     "template_id": "[YOUR TEMPLATE ID GOES HERE]",
+         "template_id": "[YOUR TEMPLATE ID GOES HERE]",
-     "tracking_settings": {
+         "tracking_settings": {
-         "subscription_tracking": {
+             "subscription_tracking": {
-             "enable": True,
+                 "enable": True,
-             "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",
+                 "html": "<html>{}</html>".format(request.args["html_tracking"]),
-             "substitution_tag": "<%click here%>",
+                 "substitution_tag": "<%click here%>",
-             "text": "If you would like to unsubscribe and stop receiving these emails <% click here %>."
+                 "text": "If you would like to unsubscribe and stop receiving these emails <% click here %>."
+             }
          }
      }
- }
  
- response = sg.client.mail.send.post(request_body=data)
+     response = sg.client.mail.send.post(request_body=data)
  
Add RFS to `sendgrid` test
## Code Before:
import sendgrid
import os


sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))

data = {
    "content": [
        {
            "type": "text/html",
            "value": "<html><p>Hello, world!</p><img src=[CID GOES HERE]></img></html>"
        }
    ],
    "from": {
        "email": "sam.smith@example.com",
        "name": "Sam Smith"
    },
    "headers": {},
    "mail_settings": {
        "footer": {
            "enable": True,
            "html": "<p>Thanks</br>The SendGrid Team</p>",
            "text": "Thanks,/n The SendGrid Team"
        },
    },
    "reply_to": {
        "email": "sam.smith@example.com",
        "name": "Sam Smith"
    },
    "send_at": 1409348513,
    "subject": "Hello, World!",
    "template_id": "[YOUR TEMPLATE ID GOES HERE]",
    "tracking_settings": {
        "subscription_tracking": {
            "enable": True,
            "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",
            "substitution_tag": "<%click here%>",
            "text": "If you would like to unsubscribe and stop receiving these emails <% click here %>."
        }
    }
}

response = sg.client.mail.send.post(request_body=data)

## Instruction:
Add RFS to `sendgrid` test
## Code After:
import sendgrid
import os
from flask import request, Flask

app = Flask(__name__)


@app.route("/sendgrid")
def send():
    sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))

    data = {
        "content": [
            {
                "type": "text/html",
                "value": "<html>{}</html>".format(request.args["html_content"])
            }
        ],
        "from": {
            "email": "sam.smith@example.com",
            "name": "Sam Smith"
        },
        "headers": {},
        "mail_settings": {
            "footer": {
                "enable": True,
                "html": "<html>{}</html>".format(request.args["html_footer"]),
                "text": "Thanks,/n The SendGrid Team"
            },
        },
        "reply_to": {
            "email": "sam.smith@example.com",
            "name": "Sam Smith"
        },
        "send_at": 1409348513,
        "subject": "Hello, World!",
        "template_id": "[YOUR TEMPLATE ID GOES HERE]",
        "tracking_settings": {
            "subscription_tracking": {
                "enable": True,
                "html": "<html>{}</html>".format(request.args["html_tracking"]),
                "substitution_tag": "<%click here%>",
                "text": "If you would like to unsubscribe and stop receiving these emails <% click here %>."
            }
        }
    }

    response = sg.client.mail.send.post(request_body=data)
