Skip to content

Commit cfb8f6d

Browse files
committed
Initial commit
1 parent 1b1b5d9 commit cfb8f6d

File tree

5 files changed

+168
-0
lines changed

5 files changed

+168
-0
lines changed

handler.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import json
2+
import re
3+
import smtplib
4+
import dns.resolver
5+
6+
def verify(event, context):
7+
verification_address = event['queryStringParameters']['email']
8+
from_address = '[email protected]'
9+
regex = '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$'
10+
match = re.match(regex, verification_address)
11+
if (match == "None"):
12+
body = {
13+
'message': 'Bad Syntax',
14+
'status': 'FALSE'
15+
}
16+
else:
17+
split_verfication_address = verification_address.split('@')
18+
domain = str(split_verfication_address[1])
19+
records = dns.resolver.query(domain, 'MX')
20+
mx_record = records[0].exchange
21+
mx_record = str(mx_record)
22+
# SMTP lib setup (use debug level for full output)
23+
server = smtplib.SMTP()
24+
server.set_debuglevel(0)
25+
# SMTP Conversation
26+
server.connect(mx_record)
27+
server.helo(server.local_hostname) ### server.local_hostname(Get local server hostname)
28+
server.mail(from_address)
29+
code, message = server.rcpt(str(verification_address))
30+
server.quit()
31+
if (code == 250):
32+
body = {
33+
'message': 'Valid email',
34+
'status': 'TRUE'
35+
}
36+
else:
37+
body = {
38+
'message': 'Invalid email',
39+
'status': 'FALSE'
40+
}
41+
return {
42+
'statusCode': 200,
43+
'body': json.dumps(body)
44+
}

package.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "email-verify",
3+
"description": "",
4+
"version": "0.1.0",
5+
"dependencies": {},
6+
"devDependencies": {
7+
"serverless-python-requirements": "^4.0.0"
8+
}
9+
}

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dnspython

serverless.yml

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Welcome to Serverless!
2+
#
3+
# This file is the main config file for your service.
4+
# It's very minimal at this point and uses default values.
5+
# You can always add more config options for more control.
6+
# We've included some commented out config examples here.
7+
# Just uncomment any of them to get that config option.
8+
#
9+
# For full config options, check the docs:
10+
# docs.serverless.com
11+
#
12+
# Happy Coding!
13+
14+
service: email-verify
15+
16+
# You can pin your service to only deploy with a specific Serverless version
17+
# Check out our docs for more details
18+
frameworkVersion: ">=1.16.0 <2.0.0"
19+
20+
plugins:
21+
- serverless-python-requirements
22+
provider:
23+
name: aws
24+
runtime: python3.6
25+
26+
# you can overwrite defaults here
27+
# stage: dev
28+
# region: us-east-1
29+
30+
# you can add statements to the Lambda function's IAM Role here
31+
# iamRoleStatements:
32+
# - Effect: "Allow"
33+
# Action:
34+
# - "s3:ListBucket"
35+
# Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] }
36+
# - Effect: "Allow"
37+
# Action:
38+
# - "s3:PutObject"
39+
# Resource:
40+
# Fn::Join:
41+
# - ""
42+
# - - "arn:aws:s3:::"
43+
# - "Ref" : "ServerlessDeploymentBucket"
44+
# - "/*"
45+
46+
# you can define service wide environment variables here
47+
# environment:
48+
# variable1: value1
49+
50+
# you can add packaging information here
51+
#package:
52+
# include:
53+
# - include-me.py
54+
# - include-me-dir/**
55+
# exclude:
56+
# - exclude-me.py
57+
# - exclude-me-dir/**
58+
59+
functions:
60+
email-verify:
61+
handler: handler.verify
62+
events:
63+
- http:
64+
path: email-verify
65+
method: get
66+
# The following are a few example events you can configure
67+
# NOTE: Please make sure to change your handler code to work with those events
68+
# Check the event documentation for details
69+
# events:
70+
# - http:
71+
# path: users/create
72+
# method: get
73+
# - s3: ${env:BUCKET}
74+
# - schedule: rate(10 minutes)
75+
# - sns: greeter-topic
76+
# - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000
77+
# - alexaSkill
78+
# - alexaSmartHome: amzn1.ask.skill.xx-xx-xx-xx
79+
# - iot:
80+
# sql: "SELECT * FROM 'some_topic'"
81+
# - cloudwatchEvent:
82+
# event:
83+
# source:
84+
# - "aws.ec2"
85+
# detail-type:
86+
# - "EC2 Instance State-change Notification"
87+
# detail:
88+
# state:
89+
# - pending
90+
# - cloudwatchLog: '/aws/lambda/hello'
91+
# - cognitoUserPool:
92+
# pool: MyUserPool
93+
# trigger: PreSignUp
94+
95+
# Define function environment variables here
96+
# environment:
97+
# variable2: value2
98+
99+
# you can add CloudFormation resource templates here
100+
#resources:
101+
# Resources:
102+
# NewResource:
103+
# Type: AWS::S3::Bucket
104+
# Properties:
105+
# BucketName: my-new-bucket
106+
# Outputs:
107+
# NewOutput:
108+
# Description: "Description for the output"
109+
# Value: "Some output value"

test.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"queryStringParameters": {
3+
"email": "[email protected]"
4+
}
5+
}

0 commit comments

Comments
 (0)