top of page
Writer's picturelekhakAI

Building an AI Email Writer: A Code Walkthrough

Updated: May 5

An example walk through for writing your AI email writer App. By the end you should have a functional web App for AI email writer. You will get all code examples and repository is hosted here.


email_type = st.selectbox("Select Business Email Type", ["Sales Pitch", "Customer Service", "Partnership Proposal", "Project Update"])
if email_type == "Sales Pitch":
product_service_name = st.text_input("Product/Service Name")
target_audience = st.text_input("Target Audience")
elif email_type == "Customer Service":
issue_description = st.text_area("Customer Issue Description")
elif email_type == "Partnership Proposal":
partner_company_name = st.text_input("Partner Company Name")
collaboration_objective = st.text_area("Collaboration Objective"
elif email_type == "Project Update":
project_name = st.text_input("Project Name")
key_achievements = st.text_area("Key Achievements")

The code snippet provided above illustrates the functionality of our AI email writer, designed to assist users in crafting various types of business emails.


Understand AI email writer code and how it works:


1. Selecting Email Type:


The st.selectbox function allows users to choose the type of business email they want to compose. The available options include "Sales Pitch," "Customer Service," "Partnership Proposal," and "Project Update." This selection determines the template and fields required for composing the specific type of email.


2. Composing Sales Pitch Email:


If the user selects "Sales Pitch" as the email type, the code prompts for input fields related to the product or service name (product_service_name) and the target audience (target_audience). These inputs are essential for personalizing the sales pitch email and tailoring it to the specific audience's needs.


3. Composing Customer Service Email:


For "Customer Service" emails, the code presents a text area where users can describe the customer issue (issue_description). This allows businesses to efficiently address customer queries and concerns while maintaining a professional tone in their responses.


4. Composing Partnership Proposal Email:


When users choose "Partnership Proposal," the code prompts for input fields such as the partner company name (partner_company_name) and the collaboration objective (collaboration_objective). These details are crucial for initiating and outlining potential partnerships or collaborations between businesses.


5. Composing Project Update Email:


Lastly, for "Project Update" emails, users are prompted to input the project name (project_name) and key achievements (key_achievements). This feature enables businesses to keep stakeholders informed about project progress, milestones achieved, and future objectives.


 

if st.button('**Write Business Email**'):
with st.status("Assigning a AI professional to write your Email..", expanded=True) as status:
if email_type == "Sales Pitch":
if not product_service_name or not target_audience:
st.error("🚫 Error: Enter all the details, least you can do..")
else:
response = sales_pitch_writer(product_service_name, target_audience, status)
if response:
st.subheader(f'**🧕🔬👩 Alwrity can make mistakes. Your Final Email for Sales Pitch!**')
st.write(response)
else:
st.write("💥**Failed to write Email. Please try again!**")
elif email_type == "Customer Service":
if not issue_description:
st.error("🚫 Error: Enter all the details, least you can do..")
else:
response = customer_service_writer(issue_description, status)
if response:
st.subheader(f'**🧕🔬👩 Alwrity can make mistakes. Your Final Email for Customer Service!**')
st.write(response)
else:
st.write("💥**Failed to write Email. Please try again!**")

How It Works:


  • Triggering Email Writing Process: When the user clicks the "Write Business Email" button, the code initiates the email writing process.


  • Status Indicator: The status indicator displays a message indicating that an AI professional is being assigned to write the email. This provides users with real-time feedback on the process.


  • Conditional Execution: Based on the selected email type, the code determines which function to call for generating the email content. For example, if the email type is "Sales Pitch," the sales_pitch_writer function is called with the provided product/service name and target audience details.


  • Error Handling: The code checks if all required details are provided. If any required field is empty, an error message is displayed, prompting the user to fill in all the details.


  • Generating Email Content: The selected function (sales_pitch_writer or customer_service_writer) generates the final email content based on the provided inputs. This content is then displayed to the user for review.


  • Feedback on Success/Failure: Depending on whether the email generation process is successful or not, appropriate messages are displayed to the user. If successful, the final email content is presented with a subheader indicating its type. If unsuccessful, a failure message is displayed, prompting the user to try again.


In the next section, we'll delve deeper into the implementation of the sales_pitch_writer and customer_service_writer functions, exploring how our AI algorithms transform user inputs into professionally crafted emails.



 

This Marks the End of Part 1. If there is interest in this blog, Alwrity, will follow up with part-2.



AI email writer code

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page