api
SMTP Mailer

Documentation

Endpoint

POST https://api.i-as.dev/api/smtp

SMTP Configuration Headers

  • server (required): The SMTP server (e.g., smtp.example.com).
  • port (required): The SMTP server port (e.g., 587).
  • secure (required): A boolean value indicating whether the connection should be secured (true or false).
  • email (required): The sender's email address (e.g., you@example.com).
  • password (required): The password or app-specific password for the email account.

Body Request

The body of the request should contain the email details as follows:

{
  "from": "email",        // The sender's email address
  "to": "email",          // The recipient's email address
  "cc": "email",          // Optional: CC recipients
  "subject": "string",    // The email subject
  "text": "string"        // The email body content
}

Example Request (JSON Body)

{
  "from": "your_email@example.com",
  "to": "to_email@example.com",
  "cc": "cc_email@example.com",
  "subject": "Test API",
  "text": "Hello, Test Email From API"
}

Response

The response will contain information about the status of the email sending process:

{
  "message": "Email sent successfully",
  "info": {
    "accepted": ["email"],
    "rejected": ["email"],
    "envelopeTime": "value",
    "messageTime": "value",
    "messageSize": "value",
    "response": "string",
    "envelope": {
      "from": "email",
      "to": ["email"]
    },
    "messageId": "string"
  }
}
  • message: A message indicating the result of the email sending attempt (e.g., "Email sent successfully").
  • info: An object containing detailed information about the sent email.
    • accepted: An array of emails that were successfully accepted.
    • rejected: An array of emails that were rejected.
    • envelopeTime: The time taken for the email envelope processing.
    • messageTime: The time taken for the message processing.
    • messageSize: The size of the email message.
    • response: The response from the SMTP server.
    • envelope: The envelope of the email, containing the sender and recipient email addresses.
    • messageId: The unique identifier for the email message.

Usage Examples

JavaScript Example
const smtpConfig = { 
  server: 'smtp.example.com', 
  port: 587, 
  secure: true, 
  email: 'your_email@example.com', 
  password: 'your_password' 
};

const emailData = { 
  from: 'your_email@example.com', 
  to: 'to_email@example.com', 
  cc: 'cc_email@example.com', 
  subject: 'Test Api', 
  text: 'Hello, Test Email From API' 
};

function sendEmail() { 
  fetch('https://api.i-as.dev/api/smtp', { 
    method: 'POST', 
    headers: { 
      'Content-Type': 'application/json', 
      'Authorization': `Basic ${btoa(`${smtpConfig.email}:${smtpConfig.password}`)}` 
    }, 
    body: JSON.stringify(emailData) 
  }) 
  .then(response => response.json()) 
  .then(data => { 
    if (data.message === 'Email sent successfully') { 
      console.log('Successfully:', data.info); 
    } else { 
      console.error('Failed to send email:', data.message); 
    } 
  }) 
  .catch(error => { 
    console.error('Error:', error); 
  }); 
}

sendEmail();
cURL Example
curl -X POST https://api.i-as.dev/api/smtp \
  -H "Content-Type: application/json" \
  -H "Authorization: Basic $(echo -n 'your_email@example.com:your_password' | base64)" \
  -H "X-SMTP-Server: smtp.example.com" \
  -H "X-SMTP-Port: 587" \
  -H "X-SMTP-Secure: true" \
  -d '{ 
    "from": "your_email@testapi.com", 
    "to": "to_email@gmail.com", 
    "cc": "cc_email@gmail.com", 
    "subject": "Test Api", 
    "text": "Hello, Test Email From API" 
  }'