> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mailchannels.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Sub-account SMTP Password

> Creates a new SMTP password for the specified sub-account.




## OpenAPI

````yaml /email-api/api-reference/openapi.yaml post /sub-account/{handle}/smtp-password
openapi: 3.0.0
info:
  contact:
    email: support@mailchannels.com
    name: MailChannels Corporation
  description: >
    This is the API reference for Email API. Here, you'll find more detailed
    information on every endpoint, including parameters, response formats, and
    error codes.
  title: Email API
  version: 1.4.0
servers:
  - url: https://api.mailchannels.net/tx/v1
security: []
tags:
  - name: Send
  - name: DKIM
  - name: Metrics
  - name: Sub-accounts
  - name: Suppression
  - name: Webhooks
  - name: Usage
  - name: Custom Tracking
paths:
  /sub-account/{handle}/smtp-password:
    post:
      tags:
        - Sub-accounts
      summary: Create Sub-account SMTP Password
      description: |
        Creates a new SMTP password for the specified sub-account.
      parameters:
        - description: Handle of the sub-account to create SMTP password for.
          in: path
          name: handle
          required: true
          schema:
            type: string
        - in: header
          name: X-Api-Key
          required: true
          schema:
            type: string
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SMTPPassword'
          description: >-
            A new SMTP password was successfully created for the specified
            sub-account.
        '403':
          description: >
            The operation is forbidden. You can't create SMTP passwords for this
            sub-account.
        '404':
          description: The specified sub-account does not exist.
        '422':
          description: >
            You have reached the limit of SMTP passwords you can create for this
            sub-account.
        '500':
          description: An unexpected internal error occurred.
      x-codeSamples:
        - label: Node.js
          lang: javascript
          source: >-
            import { MailChannels } from "mailchannels-sdk";


            const { PARENT_API_KEY, SUB_ACCOUNT_HANDLE } = process.env;

            if (!PARENT_API_KEY) throw new Error("Set PARENT_API_KEY (a
            parent-account API key) before running");

            if (!SUB_ACCOUNT_HANDLE) throw new Error("Set SUB_ACCOUNT_HANDLE
            (the sub-account to create an SMTP password for)");


            const mailchannels = new MailChannels(PARENT_API_KEY);


            const { data, error } = await
            mailchannels.subAccounts.createSmtpPassword(SUB_ACCOUNT_HANDLE);


            if (error) {
              console.error("Create SMTP password failed:", error);
              process.exit(1);
            }

            // data.smtpPassword is shown only once. Store it securely.

            console.log(data);
        - label: Python
          lang: python
          source: >-
            import os

            import sys


            import mailchannels


            parent_api_key = os.environ.get("PARENT_API_KEY")

            handle = os.environ.get("SUB_ACCOUNT_HANDLE")

            if not parent_api_key:
                sys.exit("Set PARENT_API_KEY (a parent-account API key) before running")
            if not handle:
                sys.exit("Set SUB_ACCOUNT_HANDLE (the sub-account to create an SMTP password for)")

            mailchannels.api_key = parent_api_key


            # smtp_password is shown only once in the response. Store it
            securely.

            response = mailchannels.SubAccounts.SmtpPasswords.create(handle)


            print(response)
        - label: PHP
          lang: php
          source: >-
            <?php


            require_once __DIR__ . '/vendor/autoload.php';


            use MailChannels\Client;


            $parent_api_key     = getenv('PARENT_API_KEY') or exit("Error:
            PARENT_API_KEY is not set\n");

            $sub_account_handle = getenv('SUB_ACCOUNT_HANDLE') or exit("Error:
            SUB_ACCOUNT_HANDLE is not set\n");


            $client = new Client(apiKey: $parent_api_key);


            $response =
            $client->subAccounts->smtpPasswords->create($sub_account_handle);


            // smtpPassword is shown only once. Store it securely.

            print_r($response->toArray());
components:
  schemas:
    SMTPPassword:
      properties:
        enabled:
          description: Whether the SMTP password is enabled
          type: boolean
        id:
          description: The SMTP password ID for the sub-account
          type: integer
        smtp_password:
          description: SMTP password for the sub-account
          type: string
      type: object

````