Module email
API
Declarations
ballerina/email Ballerina library
Clients
email: ImapClient
Represents an IMAP Client, which interacts with an IMAP Server.
Constructor
Gets invoked during the email:ImapClient initialization.
init (string host, string username, string password, *ImapConfiguration clientConfig)- host string - Host of the IMAP Client
- username string - Username of the IMAP Client
- password string - Password of the IMAP Client
- clientConfig *ImapConfiguration - Configurations for the IMAP Client
receiveMessage
Reads a message.
email:Message|email:Error emailResponse = imapClient->receiveMessage();
Parameters
- folder string (default DEFAULT_FOLDER) - Folder to read emails. The default value is
INBOX
- timeout decimal (default 30) - Polling timeout period in seconds.
Return Type
close
function close() returns Error?Close the client.
email:Error? closeResponse = imapClient->close();
Return Type
- Error? - An
email:Errorif the recipient failed to close the client or else()
email: PopClient
Represents a POP Client, which interacts with a POP Server.
Constructor
Gets invoked during the email:PopClient initialization.
init (string host, string username, string password, *PopConfiguration clientConfig)- host string - Host of the POP Client
- username string - Username of the POP Client
- password string - Password of the POP Client
- clientConfig *PopConfiguration - Configurations for the POP Client
receiveMessage
Reads a message.
email:Message|email:Error? emailResponse = popClient->receiveMessage();
Parameters
- folder string (default DEFAULT_FOLDER) - Folder to read the emails. The default value is
INBOX
- timeout decimal (default 30) - Polling timeout period in seconds
Return Type
close
function close() returns Error?Close the client.
email:Error? closeResponse = popClient->close();
Return Type
- Error? - An
email:Errorif the recipient failed to close the client or else()
email: SmtpClient
Represents an SMTP Client, which interacts with an SMTP Server.
Constructor
Gets invoked during the email:SmtpClient initialization.
init (string host, string username, string password, *SmtpConfiguration clientConfig)- host string - Host of the SMTP Client
- username string - Username of the SMTP Client
- password string - Password of the SMTP Client
- clientConfig *SmtpConfiguration - Configurations for SMTP Client
sendMessage
Sends an email message.
email:Error? response = smtpClient->sendMessage(email);
Parameters
- email Message - An
email:Messagemessage, which needs to be sent to the recipient
Return Type
- Error? - An
email:Errorif failed to send the message to the recipient or else()
send
function send(string|string[] to, string subject, string 'from, string body, *Options options) returns Error?Sends an email message with optional parameters.
email:Error? response = smtpClient->send(toAddress, subject, fromAddress, emailBody, sender="eve@abc.com");
Parameters
- subject string - Subject of email
- 'from string -
- body string - Text body of the email
- options *Options - Optional parameters of the email
Return Type
- Error? - An
email:Errorif failed to send the message to the recipient or else()
Service types
email: Service
Represents a Email service.
Constants
email: DEFAULT_FOLDER
Default folder to read emails.
Enums
email: Protocol
Represents protocol options.
Members
email: Security
Security type.
Members
Listeners
email: ImapListener
Represents a service listener that monitors the email server location.
Constructor
Gets invoked during the email:ImapListener initialization.
init (ImapListenerConfiguration listenerConfig)- listenerConfig ImapListenerConfiguration -
attach
Binds a service to the email:ImapListener.
email:Error? result = emailListener.attach(helloService, hello);
Parameters
- s Service - Type descriptor of the service
Return Type
- error? -
()or else aemail:Errorupon failure to register the listener
'start
function 'start() returns error?Starts the email:ImapListener.
email:Error? result = emailListener.start();
Return Type
- error? - () or else error upon failure to start the listener
detach
Stops consuming messages and detaches the service from the email:ImapListener.
email:Error? result = emailListener.detach(helloService);
Parameters
- s Service - Type descriptor of the service
Return Type
- error? -
()or else aemail:Errorupon failure to detach the service
immediateStop
function immediateStop() returns error?Stops the email:ImapListener forcefully.
email:Error? result = emailListener.immediateStop();
Return Type
- error? -
()or else aemail:Errorupon failure to stop the listener
gracefulStop
function gracefulStop() returns error?Stops the email:ImapListener gracefully.
email:Error? result = emailListener.gracefulStop();
Return Type
- error? - () or else error upon failure to stop the listener
register
Registers for the Email service.
emailListener.register(helloService, hello);
email: PopListener
Represents a service listener that monitors the email server location.
Constructor
Gets invoked during the email:PopListener initialization.
init (PopListenerConfiguration listenerConfig)- listenerConfig PopListenerConfiguration -
attach
Binds a service to the email:PopListener.
email:Error? result = emailListener.attach(helloService, hello);
Parameters
- s Service - Type descriptor of the service
Return Type
- error? -
()or else aemail:Errorupon failure to register the listener
'start
function 'start() returns error?Starts the email:PopListener.
email:Error? result = emailListener.start();
Return Type
- error? -
()or else anemail:Errorupon failure to start the listener
detach
Stops consuming messages and detaches the service from the email:PopListener.
email:Error? result = emailListener.detach(helloService);
Parameters
- s Service - Type descriptor of the service
Return Type
- error? -
()or else aemail:Errorupon failure to detach the service
immediateStop
function immediateStop() returns error?Stops the email:PopListener forcefully.
email:Error? result = emailListener.immediateStop();
Return Type
- error? -
()or else aemail:Errorupon failure to stop the listener
gracefulStop
function gracefulStop() returns error?Stops the email:PopListener gracefully.
email:Error? result = emailListener.gracefulStop();
Return Type
- error? - () or else error upon failure to stop the listener
register
Registers for the Email service.
emailListener.register(helloService, hello);
Records
email: Attachment
Email attachment.
Fields
- filePath string - File path of the attachment
- contentType string - Content Type of the attachment
email: ImapConfiguration
Configuration of the IMAP Endpoint.
Fields
- port int(default 993) - Port number of the IMAP server
- security Security(default SSL) - Type of security channel
- secureSocket? SecureSocket - Secure socket configuration
email: ImapListenerConfiguration
Configuration for Email listener endpoint.
Fields
- host string - Email server host
- username string - Email server access username
- password string - Email server access password
- pollingInterval decimal(default 30) - Periodic time interval (in seconds) to check new update
- port int(default 993) - Port number of the IMAP server
- security Security(default SSL) - Type of security channel
- secureSocket? SecureSocket - Secure socket configuration
email: Message
Email message properties.
Fields
- subject string - Subject of email
- 'from? string -
- body? string - Text typed body of the email message
- htmlBody? string - HTML typed body of the email message
- contentType? string - Content Type of the Body
- sender? string - Sender's address
- attachments? Entity|Attachment|(Entity|Attachment)[] - Email attachements
email: Options
Optional parameters for an Email message.
Fields
- htmlBody? string - HTML typed body of the email message
- contentType? string - Content Type of the Body
- sender? string - Sender's address
- attachments? Entity|Attachment|(Entity|Attachment)[] - Email attachements
email: PopConfiguration
Configuration of the POP Endpoint.
Fields
- port int(default 995) - Port number of the POP server
- security Security(default SSL) - Type of security channel
- secureSocket? SecureSocket - Secure socket configuration
email: PopListenerConfiguration
Configuration for Email listener endpoint.
Fields
- host string - Email server host
- username string - Email server access username
- password string - Email server access password
- pollingInterval decimal(default 30) - Periodic time interval (in seconds) to check new update
- port int(default 995) - Port number of the POP server
- security Security(default SSL) - Type of security channel
- secureSocket? SecureSocket - Secure socket configuration
email: SecureSocket
Secure Socket configuration.
Fields
- cert string - Server certificate path
- ciphers? string[] - Ciper used
- verifyHostName boolean(default true) - Enable hostname verification
email: SmtpConfiguration
Configuration of the SMTP Endpoint.
Fields
- port int(default 465) - Port number of the SMTP server
- security Security(default SSL) - Type of security channel
- secureSocket? SecureSocket - Secure socket configuration
Errors
email: Error
Defines the common error type for the module.
Import
import ballerina/email;Metadata
Released date: 11 months ago
Version: 2.11.0
License: Apache-2.0
Compatibility
Platform: java21
Ballerina version: 2201.11.0-20241209-162400-0c015833
GraalVM compatible: Yes
Pull count
Total: 3
Current verison: 0
Weekly downloads
Keywords
SMTP
POP
POP3
IMAP
Contributors