Modules@robinpath/email
email

@robinpath/email

0.1.4Node.jsPublic

SMTP email sending and address parsing for RobinPath

Email

SMTP email sending with transports, attachments, address parsing, and Ethereal test accounts

Package: @robinpath/email | Category: Utility | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the email module when you need to:

  • Create a named SMTP transport for sending emails -- Use email.createTransport to perform this operation
  • Send an email with full options (to, subject, body, attachments, etc.) -- Use email.send to perform this operation
  • Send a simple email with just to, subject, and body -- Use email.sendQuick to perform this operation
  • Verify SMTP connection to the mail server -- Use email.verify to perform this operation
  • Validate an email address format -- Use email.isValid to perform this operation

Quick Reference

FunctionDescriptionReturns
createTransportCreate a named SMTP transport for sending emailsTransport configuration
sendSend an email with full options (to, subject, body, attachments, etc.){messageId, accepted, rejected, response}
sendQuickSend a simple email with just to, subject, and body{messageId, accepted, rejected}
verifyVerify SMTP connection to the mail server{connected: boolean, error?: string}
isValidValidate an email address formatTrue if email format is valid
parseAddressParse an email address string into name and address parts{name, address, full}
parseAddressListParse a comma-separated list of email addressesArray of {name, address, full} objects
extractDomainExtract the domain part from an email addressDomain part (e.g. 'example.com')
buildAddressBuild a formatted email address from name and emailFormatted address like '"Name" <email>'
closeClose a transport connectionTrue if transport was closed
createTestAccountCreate an Ethereal test account for development (no real emails sent){name, user, pass, smtp, web}
getTestUrlGet the Ethereal preview URL for a test emailURL to preview the email or null

Functions

createTransport

Create a named SMTP transport for sending emails

Module: email | Returns: object -- Transport configuration

email.createTransport "gmail" {"service": "gmail", "user": "me@gmail.com", "pass": "app-password"}
ParameterTypeRequiredDescription
namestringNoTransport name (default: 'default')
optionsobjectYes{host, port, secure, service, user, pass, tls}

send

Send an email with full options (to, subject, body, attachments, etc.)

Module: email | Returns: object -- {messageId, accepted, rejected, response}

email.send "gmail" {"to": "bob@example.com", "subject": "Hello", "text": "Hi there"}
ParameterTypeRequiredDescription
transportstringYesTransport name
optionsobjectYes{from, to, subject, text, html, body, cc, bcc, replyTo, attachments, priority, headers}

sendQuick

Send a simple email with just to, subject, and body

Module: email | Returns: object -- {messageId, accepted, rejected}

email.sendQuick "gmail" "bob@example.com" "Hello" "Hi Bob!"
ParameterTypeRequiredDescription
transportstringYesTransport name
tostringYesRecipient email
subjectstringYesEmail subject
bodystringYesEmail body (text or HTML)
fromstringNoSender email (optional)

verify

Verify SMTP connection to the mail server

Module: email | Returns: object -- {connected: boolean, error?: string}

email.verify "gmail"
ParameterTypeRequiredDescription
transportstringYesTransport name

isValid

Validate an email address format

Module: email | Returns: boolean -- True if email format is valid

email.isValid "user@example.com"
ParameterTypeRequiredDescription
emailstringYesEmail address to validate

parseAddress

Parse an email address string into name and address parts

Module: email | Returns: object -- {name, address, full}

email.parseAddress "John Doe <john@example.com>"
ParameterTypeRequiredDescription
addressstringYesEmail address (e.g. 'John Doe john@example.com')

parseAddressList

Parse a comma-separated list of email addresses

Module: email | Returns: array -- Array of {name, address, full} objects

email.parseAddressList "Alice <a@b.com>, Bob <b@b.com>"
ParameterTypeRequiredDescription
addressesstringYesComma-separated email addresses

extractDomain

Extract the domain part from an email address

Module: email | Returns: string -- Domain part (e.g. 'example.com')

email.extractDomain "user@example.com"
ParameterTypeRequiredDescription
emailstringYesEmail address

buildAddress

Build a formatted email address from name and email

Module: email | Returns: string -- Formatted address like '"Name" <email>'

email.buildAddress "John Doe" "john@example.com"
ParameterTypeRequiredDescription
namestringYesDisplay name
emailstringYesEmail address

close

Close a transport connection

Module: email | Returns: boolean -- True if transport was closed

email.close "gmail"
ParameterTypeRequiredDescription
transportstringYesTransport name

createTestAccount

Create an Ethereal test account for development (no real emails sent)

Module: email | Returns: object -- {name, user, pass, smtp, web}

email.createTestAccount
ParameterTypeRequiredDescription
(none)NoCall with no arguments

getTestUrl

Get the Ethereal preview URL for a test email

Module: email | Returns: string -- URL to preview the email or null

email.getTestUrl $messageId
ParameterTypeRequiredDescription
messageIdstringYesMessage ID from send result

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Transport "..." not found. Create it first with email.createTransport.Check the error message for details
Transport "..." not found.Check the error message for details
@desc "Create transport and validate result"
do
  set $result as email.createTransport "gmail" {"service": "gmail", "user": "me@gmail.com", "pass": "app-password"}
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate TestUrl

Retrieve all items and loop through them.

@desc "Get test url and iterate results"
do
  set $result as email.getTestUrl $messageId
  each $item in $result
    print $item
  end
enddo

2. Create a new item with createTransport

Create a new resource and capture the result.

set $result as email.createTransport "gmail" {"service": "gmail", "user": "me@gmail.com", "pass": "app-password"}
print "Created: " + $result

3. Check before creating

List existing items and only create if needed.

@desc "Get test url and create transport"
do
  set $existing as email.getTestUrl $messageId
  if $existing == null
    email.createTransport "gmail" {"service": "gmail", "user": "me@gmail.com", "pass": "app-password"}
    print "Item created"
  else
    print "Item already exists"
  end
enddo

4. Multi-step Email workflow

Chain multiple email operations together.

@desc "Create transport, send, and more"
do
  set $r_createTransport as email.createTransport "gmail" {"service": "gmail", "user": "me@gmail.com", "pass": "app-password"}
  set $r_send as email.send "gmail" {"to": "bob@example.com", "subject": "Hello", "text": "Hi there"}
  set $r_sendQuick as email.sendQuick "gmail" "bob@example.com" "Hello" "Hi Bob!"
  print "All operations complete"
enddo

5. Safe createTransport with validation

Check results before proceeding.

@desc "Create transport and validate result"
do
  set $result as email.createTransport "gmail" {"service": "gmail", "user": "me@gmail.com", "pass": "app-password"}
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.4latest1 months ago
Install
$ robinpath add @robinpath/email

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.4
LicenseMIT
Unpacked Size11.6 KB
Versions1
Weekly Downloads34
Total Downloads34
Stars0
Last Publish1 months ago
Created1 months ago

Keywords

Category

utilities