Unison Help

- Unison Kernel
- Pthreads
- pthread_create()
- pthread_exit()
- pthread_self()
- pthread_equal()
- pthread_join()
- pthread_detach()
- pthread_setschedparam()
- pthread_getschedparam()
- pthread_attr_init()
- pthread_attr_destroy()
- pthread_attr_setstackaddr()
- pthread_attr_getstackaddr()
- pthread_attr_setstacksize()
- pthread_attr_getstacksize()
- pthread_attr_setschedparam()
- pthread_attr_getschedparam()
- pthread_attr_setdetachstate()
- pthread_attr_getdetachstate()
- pthread_stackinfo()
- pthread_setprio()
- pthread_getprio()
- sched_get_priority_max()
- sched_get_priority_min()
- sched_yield()
- Pthread Cancellation
- Mutex
- Semaphores
- Message Queues
- Conditional Variables
- Barriers
- Timers
- Clocks
- Memory Allocation
- Rendezvous
- Interrupts
- Directory Services
- Miscellaneous
- Pthreads
- Unison I/O Library
- Unison STDIO Library
- STDIO Library Calls
- clearerr()
- dprintf()
- fclose()
- fdopen()
- feof()
- ferror()
- fileno()
- fflush()
- fgetc()
- fgetpos()
- fgets()
- fopen()
- fprintf()
- fputc()
- fputs()
- fread()
- freopen()
- fscanf()
- fseek()
- fseeko()
- fsetpos()
- ftell()
- ftello()
- fwrite()
- getc()
- getc_unlocked()
- getchar()
- getchar_unlocked()
- getdelim()
- getline()
- gets()
- get_stderr_ptr()
- get_stdin_ptr()
- get_stdout_ptr()
- noperprintf()
- perprintf()
- perror()
- posix_compat()
- printf()
- putc()
- putc_unlocked()
- putchar()
- putchar_unlocked()
- puts()
- remove()
- rewind()
- scanf()
- setbuf()
- setvbuf()
- snprintf()
- sprintf()
- sscanf()
- stderr_init()
- stderr_close()
- stdin_init()
- stdin_close()
- stdout_init()
- stdout_close()
- vdprintf()
- vscanf()
- vsscanf()
- vfscanf()
- vprintf()
- vsnprintf()
- vsprintf()
- vfprintf()
- ungetc()
- Do-nothing Stubs
- STDIO Library Calls
- Unison LIBC Library
- Unison I/O Servers
- Graphics, Camera, Video, Audio
- Network Protocols
- TCP and UDP Server - tcpd
- DHCP Client Service - dhcp client
- DHCP Server - dhcpd
- Telnet Server - telnetd
- Tiny FTP Server - tftpd
- Point to Point - pppd
- Network Translation - NAT with PAT
- Firewall
- Tiny HTTP Server - thttpd
- Tiny HTTP Server with TLS
- POP3 Server
- Simple Mail Transfer Protocol Services (SMTP)
- Bootp Protocol
- File Transfer Protocol Server (FTP)
- File Transfer Client Services
- RPC / XDR
- DNS Client
- HTTP/HTTPS Client
- REST Client
- AutoIP Service - autoip client
- mDNS server - mdnsd
- SNTP Client
- SNMP Agent - Snmpd server
- SSL/TLS library
- SSH server
- IP security
- Power Control
- Serial I/O
- System Services
- Universal Serial Bus (USB)
- Wireless
- Remedy Tools for Unison
7.12. Simple Mail Transfer Protocol Services (SMTP) #
NAME
Simple Mail Transfer Protocol Services – Smtp
SYNOPSIS
#include <smtp.h>
int smtp_accounts_setup(struct smtp_account_config * smtp_account_config, struct smtp_timout* timeout);
iint smtp_send_mail(struct smtp_mail_attribute * smtp_mail_attribute, int sock, int ssl_flag, SSL *ssl);
DESCRIPTION
Simple Mail Transfer Protocol (SMTP) is an Internet standard for electronic mail (e-mail) transmission across Internet Protocol (IP) networks. SMTP connections can be secured by SSL/TLS. SMTP component also may be used together with DNS, DHCP, SNTP and File System components.
SPECIFIC OPTIONS (Compile time)
Option | Default | Description | Values | Placement |
---|---|---|---|---|
_SMTP_USE_SSLTLS | 1 | Enables using of SSL/TLS by SMTP component. | Dec: 0 | 1 | Library |
WAIT_ANSWER_INTERVAL_US | 200000 | Time interval in microseconds for waiting of answer. | Decimal | Library |
_SMTP_USE_SSL | 1 | Enables using of SSL/TLS in demo project. | Dec: 0 | 1 | Demo |
USER EVENTS FUNCTIONS
Initialization of client.
int smtp_accounts_setup(struct smtp_account_config * smtp_account_config, struct smtp_timout* _smtp_timout);
Client setting:
struct smtp_account_config{ char* hostname; char* client_mail; char* client_login; char* client_pass; char* smtp_server; };
hostname - name of host client_mail - email address of host client_login - login of host for authentication client_pass - password of host for authentication smtp_server - name server for send emails
Time waiting for a response from mail server :
struct smtp_timout { int connect; int mail; int rcpt; int data_start int data_block; int data_end; }; connect - time wating answer from server on connect mail - time wating answer from server on command "MAIL FROM" rcpt - time wating answer from server on command "RCPT TO" data_start - time wating answer from server on command "DATA" data_block - time wating answer from server on send conntent mail data_end - time wating answer from server on command "QUIT"
If user didn’t specify timeout value, then default “#define DEF_TIOUT 1500” value will be used.
Function send mails:
int smtp_send_mail(struct smtp_mail_attribute * smtp_mail_attribute, int sock, int ssl_flag, SSL *ssl);
Options for sending emails:
struct smtp_mail_attribute{ char* data; int cnt_address; char* address_to_send[10]; char* subject; }; data - contents of the emails cnt_address - number of address address_to_send - addresses of emails subject - subject of emails ssl_flag - enable/disable (1/0) use ssl/tls ssl - ssl object
EXAMPLE
static struct smtp_account_config smtp_account_config; static struct smtp_mail_attribute smtp_mail_attribute; static struct smtp_timout smtp_timeout; ... { int _port; int sock_out, errval; struct sockaddr_in server; char ipstr[INET6_ADDRSTRLEN]; int ssl_flag; int result; SSL *ssl = NULL; ... ssl_flag = ENABLE_SSLTLS; ... xprintf("Start smtp client\n"); /* * Set configuration smtp client * */ //host name smtp_account_config.hostname = "hello.org"; // smtp server smtp_account_config.smtp_server =""; //enter smtp server for example: "smtp.gmail.com" //port server if(ssl_flag == ENABLE_SSLTLS) _port = 465; else _port = 25; // our mail smtp_account_config.client_mail = "";// enter your mail for example:"test_example@gmail.com" //login smtp_account_config.client_login = ""; // enter your login for example:"test_example" //password smtp_account_config.client_pass = ""; // enter your password for example:"1111" //subject smtp_mail_attribute.subject = "test"; //data mail smtp_mail_attribute.data = "this is my mail"; //count of address smtp_mail_attribute.cnt_address = 2; //count of mail address, for example set 2 if you send mail on two address //destination mail smtp_mail_attribute.address_to_send[0] = ""; // enter destination mail first address smtp_mail_attribute.address_to_send[1] = ""; // enter destination mail second address //set timeout smtp protocol smtp_timeout.connect = 25; smtp_timeout.mail = 25; smtp_timeout.rcpt = 25; smtp_timeout.data_start = 25; smtp_timeout.data_block = 25; smtp_timeout.data_end = 25; ... smtp_accounts_setup(&smtp_account_config, &smtp_timeout); ... server.sin_family = AF_INET; server.sin_addr.s_addr = inet_addr(ipstr); server.sin_port = htons(_port); /* SMTP PORT */ // Get a socket for the connection sock_out = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); ... #if _SMTP_USE_SSL > 0 if (ssl_flag){ result = smtp_send_mail(&smtp_mail_attribute, sock_out, ssl_flag, ssl); } #endif if (ssl_flag == 0){ xprintf("without ssl\n"); result = smtp_send_mail(&smtp_mail_attribute, sock_out, ssl_flag, NULL); } if (result){ xprintf("Smtp errors: %d (see smtp.h)\n", result); } #if _SMTP_USE_SSL > 0 if (ssl_flag){ SSL_shutdown(ssl); SSL_free(ssl); } #endif close(sock_out); ... }
NOTES
There is a demo available for the Unison and DSPnano SMTP Client which can be found in installdir/demos.
SEE ALSO
IPv4 only server, IPv4/IPv6 server, DNS Client, SNTP Client, Multimedia File Server, FAT File System