Blog Logo

12 Sep 2023 ~ 2 min read

Go Contact API & Send Email


This API is designed to handle contact form submissions, store contact information in a MongoDB database, and send a confirmation email. It provides endpoints to submit contact information and receive confirmation messages.

Table of Contents

Getting Started

Prerequisites

Before running the API, ensure you have the following prerequisites installed:

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/contact-api.git
  2. Navigate to the project directory:

    cd contact-api
  3. Create a .env file in the project root and configure the following environment variables:

    MONGODB_URI=your-mongodb-uri
    SMTP_HOST=your-smtp-host
    SMTP_PORT=your-smtp-port
    SMTP_USERNAME=your-smtp-username
    SMTP_PASSWORD=your-smtp-password
    PORT=your-api-port
  4. Build and run the API:

    go build
    ./contact-api

The API should now be running on the specified port.

Usage

API Endpoints

Submit Contact Information

  • Endpoint: /api/contact
  • Method: POST
  • Request Body:
    {
      "firstName": "John",
      "lastName": "Doe",
      "email": "johndoe@example.com",
      "linkedin": "linkedin.com/in/johndoe",
      "tech": "Go, JavaScript",
      "message": "Hello, I'm interested in your services."
    }
  • Response:
    {
      "message": "Data saved successfully and email sent!"
    }

Environment Variables

  • MONGODB_URI: MongoDB connection URI.
  • SMTP_HOST: SMTP server host.
  • SMTP_PORT: SMTP server port.
  • SMTP_USERNAME: SMTP server username.
  • SMTP_PASSWORD: SMTP server password.
  • PORT: Port on which the API should run.

Contributing

Contributions are welcome! Please feel free to open issues or pull requests.

Developed By

Francisco Inoque


Headshot of Francisco Inoque

Hello, I'm Francisco Inoque, an experienced Back-End Developer with expertise in Node.js, Go, and Python. I thrive on solving complex development challenges and am eager to contribute to innovative projects. Let's connect and discuss how I can help you achieve your goals efficiently!