{"id":15049464,"url":"https://github.com/somnisoft/smtp-client","last_synced_at":"2025-04-10T02:11:17.022Z","repository":{"id":55499442,"uuid":"138437603","full_name":"somnisoft/smtp-client","owner":"somnisoft","description":"SMTP Client Library in C","archived":false,"fork":false,"pushed_at":"2022-11-07T15:56:51.000Z","size":605,"stargazers_count":120,"open_issues_count":9,"forks_count":33,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-10T02:10:41.165Z","etag":null,"topics":["c89","cross-platform","doxygen-documentation","openssl-support","public-domain","smtp","smtp-client","smtp-library","smtp-mail","smtpclient"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/somnisoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-23T22:27:39.000Z","updated_at":"2025-03-07T01:21:26.000Z","dependencies_parsed_at":"2022-08-15T01:50:38.262Z","dependency_job_id":null,"html_url":"https://github.com/somnisoft/smtp-client","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somnisoft%2Fsmtp-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somnisoft%2Fsmtp-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somnisoft%2Fsmtp-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somnisoft%2Fsmtp-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/somnisoft","download_url":"https://codeload.github.com/somnisoft/smtp-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142905,"owners_count":21054671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c89","cross-platform","doxygen-documentation","openssl-support","public-domain","smtp","smtp-client","smtp-library","smtp-mail","smtpclient"],"created_at":"2024-09-24T21:20:36.424Z","updated_at":"2025-04-10T02:11:16.988Z","avatar_url":"https://github.com/somnisoft.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# smtp-client\n\nThis is an SMTP client library written in C which can get included\ndirectly into another program.\n\nThis library has been released into the public domain using\n[CC0](https://creativecommons.org/publicdomain/zero/1.0/).\n\nOfficial repository location:\n[www.somnisoft.com/smtp-client](https://www.somnisoft.com/smtp-client)\n\n## Feature list\n* C89\n* Cross-platform (POSIX, BSD, MacOS, Windows)\n* Send attachments\n* Send custom email headers\n* Specify multiple TO, CC, and BCC recipients\n* Simple API and simple error handling (see Examples section below)\n* Optional OpenSSL TLS connection and authentication methods\n* Test cases with 100% code and branch coverage\n* Doxygen with 100% documentation including the test code\n* Free software (permissive - CC0)\n\nSupports the following connection methods:\n* No encryption\n* STARTTLS (requires OpenSSL)\n* TLS direct connection (requires OpenSSL)\n\nSupports the following authentication methods:\n* none\n* PLAIN\n* LOGIN\n* CRAM-MD5 (requires OpenSSL)\n\nTo include the library into your application, simply copy the src/smtp.h and\nsrc/smtp.c files into your project directory. Then include the smtp.h header\ninto your C file, compile smtp.c, and include the resulting object file into\nthe build system.\n\n## Examples\nThe following example code demonstrates how to use the library.\n\n```C\n#include \u003cstdio.h\u003e\n#include \"smtp.h\"\n#define MAIL_SERVER              \"mail.example.com\"\n#define MAIL_PORT                \"587\"\n#define MAIL_CONNECTION_SECURITY SMTP_SECURITY_STARTTLS\n#define MAIL_FLAGS               (SMTP_DEBUG         | \\\n                                  SMTP_NO_CERT_VERIFY) /* Do not verify cert. */\n#define MAIL_CAFILE              NULL\n#define MAIL_AUTH                SMTP_AUTH_PLAIN\n#define MAIL_USER                \"mail@example.com\"\n#define MAIL_PASS                \"password\"\n#define MAIL_FROM                \"mail@example.com\"\n#define MAIL_FROM_NAME           \"From Name\"\n#define MAIL_SUBJECT             \"Subject Line\"\n#define MAIL_BODY                \"Email Body\"\n#define MAIL_TO                  \"to@example.com\"\n#define MAIL_TO_NAME             \"To Name\"\nint main(void)\n{\n  struct smtp *smtp;\n  int rc;\n  rc = smtp_open(MAIL_SERVER,\n                 MAIL_PORT,\n                 MAIL_CONNECTION_SECURITY,\n                 MAIL_FLAGS,\n                 MAIL_CAFILE,\n                 \u0026smtp);\n  rc = smtp_auth(smtp,\n                 MAIL_AUTH,\n                 MAIL_USER,\n                 MAIL_PASS);\n  rc = smtp_address_add(smtp,\n                        SMTP_ADDRESS_FROM,\n                        MAIL_FROM,\n                        MAIL_FROM_NAME);\n  rc = smtp_address_add(smtp,\n                        SMTP_ADDRESS_TO,\n                        MAIL_TO,\n                        MAIL_TO_NAME);\n  rc = smtp_header_add(smtp,\n                       \"Subject\",\n                       MAIL_SUBJECT);\n  rc = smtp_attachment_add_mem(smtp,\n                               \"test.txt\",\n                               \"Test email attachment.\",\n                               -1);\n  rc = smtp_mail(smtp,\n                 MAIL_BODY);\n  rc = smtp_close(smtp);\n  if(rc != SMTP_STATUS_OK){\n    fprintf(stderr, \"smtp failed: %s\\n\", smtp_status_code_errstr(rc));\n    return 1;\n  }\n  return 0;\n}\n```\n\nPlace the code snippet above into a file named 'test.c' and change each #define\nto the appropriate values for your mail server. Then copy smtp.c and smtp.h\ninto the same directory and run the following commands to compile with OpenSSL\nsupport.\n\ncc -DSMTP_OPENSSL smtp.c -c -o smtp.o\n\ncc -DSMTP_OPENSSL test.c -c -o test.o\n\ncc test.o smtp.o -o smtp_test -lssl -lcrypto\n\nIf you do not need OpenSSL support, remove the -DSMTP_OPENSSL and the\n-lssl and -lcrypto arguments. The commands as above should create an\nexecutable called 'smtp_test' which can send a test email using the specified\nmail server.\n\nA minimum amount of error checking has been included. Note that in the above\nexample, the program checks for an error at the end of the mail session after\ncalling smtp_close. We can do this because if an error occurs in any of the\nprior functions, the error will continue to propagate through any future\nfunction calls until either closing the SMTP context using smtp_close or by\nresetting the error condition using smtp_status_code_clear.\n\nThe following example demonstrates how to send an HTML email by overriding the\nContent-Type header. When overriding this header, any attachments added using\nthe smtp_attachment_add\\* functions will get ignored. The application must\ngenerate the appropriate MIME sections (if needed) when overriding this\nheader.\n\n```C\n#include \u003cstdio.h\u003e\n#include \"smtp.h\"\n#define MAIL_SERVER              \"localhost\"\n#define MAIL_PORT                \"25\"\n#define MAIL_CONNECTION_SECURITY SMTP_SECURITY_NONE\n#define MAIL_FLAGS               SMTP_DEBUG\n#define MAIL_CAFILE              NULL\n#define MAIL_AUTH                SMTP_AUTH_NONE\n#define MAIL_USER                \"mail@somnisoft.com\"\n#define MAIL_PASS                \"password\"\n#define MAIL_FROM                \"mail@somnisoft.com\"\n#define MAIL_FROM_NAME           \"From Name\"\n#define MAIL_SUBJECT             \"Subject Line\"\n#define MAIL_TO                  \"mail@somnisoft.com\"\n#define MAIL_TO_NAME             \"To Name\"\nint main(void){\n  struct smtp *smtp;\n  enum smtp_status_code rc;\n  const char *const email_body =\n  \"\u003chtml\u003e\\n\"\n  \" \u003chead\u003e\u003ctitle\u003eHTML Email\u003c/title\u003e\u003c/head\u003e\\n\"\n  \" \u003cbody\u003e\\n\"\n  \"  \u003ch1\u003eH1\u003c/h1\u003e\\n\"\n  \"  \u003ch2\u003eH2\u003c/h1\u003e\\n\"\n  \"  \u003ch3\u003eH3\u003c/h1\u003e\\n\"\n  \"  \u003ch4\u003eH4\u003c/h1\u003e\\n\"\n  \"  \u003ch5\u003eH5\u003c/h1\u003e\\n\"\n  \"  \u003ch6\u003eH6\u003c/h1\u003e\\n\"\n  \" \u003c/body\u003e\\n\"\n  \"\u003c/html\u003e\\n\";\n  smtp_open(MAIL_SERVER,\n            MAIL_PORT,\n            MAIL_CONNECTION_SECURITY,\n            MAIL_FLAGS,\n            MAIL_CAFILE,\n            \u0026smtp);\n  smtp_auth(smtp,\n            MAIL_AUTH,\n            MAIL_USER,\n            MAIL_PASS);\n  smtp_address_add(smtp,\n                   SMTP_ADDRESS_FROM,\n                   MAIL_FROM,\n                   MAIL_FROM_NAME);\n  smtp_address_add(smtp,\n                   SMTP_ADDRESS_TO,\n                   MAIL_TO,\n                   MAIL_TO_NAME);\n  smtp_header_add(smtp,\n                  \"Subject\",\n                  MAIL_SUBJECT);\n  smtp_header_add(smtp,\n                  \"Content-Type\",\n                  \"text/html\");\n  smtp_mail(smtp, email_body);\n  rc = smtp_close(smtp);\n  if(rc != SMTP_STATUS_OK){\n    fprintf(stderr, \"smtp failed: %s\\n\", smtp_status_code_errstr(rc));\n    return 1;\n  }\n  return 0;\n}\n```\n\n## Technical Documentation\nSee the [Technical Documentation](\nhttps://www.somnisoft.com/smtp-client/technical-documentation/index.html)\ngenerated from Doxygen.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsomnisoft%2Fsmtp-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsomnisoft%2Fsmtp-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsomnisoft%2Fsmtp-client/lists"}