{"id":2259,"date":"2022-07-08T14:06:00","date_gmt":"2022-07-08T09:06:00","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=2259"},"modified":"2022-07-08T14:06:03","modified_gmt":"2022-07-08T09:06:03","slug":"send-birthday-wish-as-sms-mail-with-python3-fast2sms-api","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/","title":{"rendered":"Send Birthday Wish as SMS\/Mail with Python 3 Fast2SMS API"},"content":{"rendered":"\n<p>Python 3 Fast2SMS API Bot to Send Birthday Wish as SMS or Mail to Multiple Contacts on Phone in Command Line<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">code.py<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\"># import required packages\nimport pandas as pd\nimport datetime\nimport smtplib\nimport time\nimport requests\nfrom win10toast import ToastNotifier\n\n# your gmail credentials here\nGMAIL_ID = 'your_email_here'\nGMAIL_PWD = 'your_password_here'\n\n# for desktop notification\ntoast = ToastNotifier()\n\n# define a function for sending email\ndef sendEmail(to, sub, msg):\n\n  # connection to gmail\n  gmail_obj = smtplib.SMTP('smtp.gmail.com', 587)\n  \n  # starting the session\n  gmail_obj.starttls()  \n  \n  # login using credentials\n  gmail_obj.login(GMAIL_ID, GMAIL_PWD)\n  \n  # sending email\n  gmail_obj.sendmail(GMAIL_ID, to,\n        f&quot;Subject : {sub}\\n\\n{msg}&quot;)\n  \n  # quit the session\n  gmail_obj.quit()\n  \n  print(&quot;Email sent to &quot; + str(to) + &quot; with subject &quot;\n    + str(sub) + &quot; and message :&quot; + str(msg))\n  \n  toast.show_toast(&quot;Email Sent!&quot; ,\n          f&quot;{name} was sent e-mail&quot;,\n          threaded = True,\n          icon_path = None,\n          duration = 6)\n\n  while toast.notification_active():\n    time.sleep(0.1)\n\n# define a function for sending sms  \ndef sendsms(to, msg, name, sub):\n\n  url = &quot;https:\/\/www.fast2sms.com\/dev\/bulk&quot;\n  payload = f&quot;sender_id=FSTSMS&amp;message={msg}&amp;language=english&amp;route=p&amp;numbers={to}&quot;\n  \n  headers = {\n    'authorization': &quot;API_KEY_HERE&quot;,\n    'Content-Type': &quot;application\/x-www-form-urlencoded&quot;,\n    'Cache-Control': &quot;no-cache&quot;,\n    }\n\n  response_obj = requests.request(&quot;POST&quot;, url,\n                data = payload,\n                headers = headers)\n  print(response_obj.text)\n  print(&quot;SMS sent to &quot; + str(to) + &quot; with subject :&quot; +\n    str(sub) + &quot; and message :&quot; + str(msg))\n  \n  toast.show_toast(&quot;SMS Sent!&quot; ,\n          f&quot;{name} was sent message&quot;,\n          threaded = True,\n          icon_path = None,\n          duration = 6)\n\n  while toast.notification_active():\n    time.sleep(0.1)\n\n# driver code\nif __name__==&quot;__main__&quot;:\n\n  # read the excel sheet having all the details\n  dataframe = pd.read_excel(&quot;excelsheet.xlsx&quot;)\n  \n  # today date in format : DD-MM\n  today = datetime.datetime.now().strftime(&quot;%d-%m&quot;)\n  \n  # current year in format : YY\n  yearNow = datetime.datetime.now().strftime(&quot;%Y&quot;)\n  \n  # writeindex list\n  writeInd = []                        \n\n  for index,item in dataframe.iterrows():\n  \n    msg = &quot;Many Many Happy Returns of the day dear &quot; + str(item['NAME'])\n        \n    # stripping the birthday in excel\n    # sheet as : DD-MM\n    bday = item['Birthday'].strftime(&quot;%d-%m&quot;)  \n    \n    # condition checking\n    if (today == bday) and yearNow not in str(item['Year']):\n      \n      # calling the sendEmail function\n      sendEmail(item['Email'], &quot;Happy Birthday&quot;,\n          msg)\n      \n      # calling the sendsms function\n      sendsms(item['Contact'], msg, item['NAME'],\n          &quot;Happy Birthday&quot;)\n      \n      writeInd.append(index)                \n\n  for i in writeInd:\n  \n    yr = dataframe.loc[i,'Year']\n    \n    # this will record the years in which\n    # email has been sent\n    dataframe.loc[i,'Year'] = str(yr) + ',' + str(yearNow)      \n\n  dataframe.to_excel('excelsheet.xlsx',\n        index = False)<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Python 3 Fast2SMS API Bot to Send Birthday Wish as SMS or Mail to Multiple Contacts on Phone in Command Line code.py<\/p>\n","protected":false},"author":1,"featured_media":1762,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-2259","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Send Birthday Wish as SMS\/Mail with Python 3 Fast2SMS API<\/title>\n<meta name=\"description\" content=\"Python 3 Fast2SMS API Bot to Send Birthday Wish as SMS or Mail to Multiple Contacts on Phone in Command Line code.py # import required packages import\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Send Birthday Wish as SMS\/Mail with Python 3 Fast2SMS API\" \/>\n<meta property=\"og:description\" content=\"Python 3 Fast2SMS API Bot to Send Birthday Wish as SMS or Mail to Multiple Contacts on Phone in Command Line code.py # import required packages import\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-08T09:06:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-08T09:06:03+00:00\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Send Birthday Wish as SMS\/Mail with Python 3 Fast2SMS API","description":"Python 3 Fast2SMS API Bot to Send Birthday Wish as SMS or Mail to Multiple Contacts on Phone in Command Line code.py # import required packages import","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/","og_locale":"en_US","og_type":"article","og_title":"Send Birthday Wish as SMS\/Mail with Python 3 Fast2SMS API","og_description":"Python 3 Fast2SMS API Bot to Send Birthday Wish as SMS or Mail to Multiple Contacts on Phone in Command Line code.py # import required packages import","og_url":"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2022-07-08T09:06:00+00:00","article_modified_time":"2022-07-08T09:06:03+00:00","author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"Send Birthday Wish as SMS\/Mail with Python 3 Fast2SMS API","datePublished":"2022-07-08T09:06:00+00:00","dateModified":"2022-07-08T09:06:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/"},"wordCount":34,"commentCount":0,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/","url":"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/","name":"Send Birthday Wish as SMS\/Mail with Python 3 Fast2SMS API","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","datePublished":"2022-07-08T09:06:00+00:00","dateModified":"2022-07-08T09:06:03+00:00","description":"Python 3 Fast2SMS API Bot to Send Birthday Wish as SMS or Mail to Multiple Contacts on Phone in Command Line code.py # import required packages import","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","width":880,"height":495,"caption":"Default Featured Image"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/send-birthday-wish-as-sms-mail-with-python3-fast2sms-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Send Birthday Wish as SMS\/Mail with Python 3 Fast2SMS API"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2259","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=2259"}],"version-history":[{"count":0,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2259\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/1762"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=2259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=2259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=2259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}