master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24/* <DESC>
25 * Send SMTP email using implicit SSL
26 * </DESC>
27 */
28#include <stdio.h>
29#include <string.h>
31#include <curl/curl.h>
33/* This is a simple example showing how to send mail using libcurl's SMTP
34 * capabilities. It builds on the smtp-mail.c example to add authentication
35 * and, more importantly, transport security to protect the authentication
36 * details from being snooped.
37 *
38 * Note that this example requires libcurl 7.20.0 or above.
39 */
41#define FROM_MAIL "<sender@example.com>"
42#define TO_MAIL "<recipient@example.com>"
43#define CC_MAIL "<info@example.com>"
45static const char payload_text[] =
46 "Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n"
47 "To: " TO_MAIL "\r\n"
48 "From: " FROM_MAIL "\r\n"
49 "Cc: " CC_MAIL "\r\n"
50 "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@"
51 "rfcpedant.example.org>\r\n"
52 "Subject: SMTP example message\r\n"
53 "\r\n" /* empty line to divide headers from body, see RFC 5322 */
54 "The body of the message starts here.\r\n"
55 "\r\n"
56 "It could be a lot of lines, could be MIME encoded, whatever.\r\n"
57 "Check RFC 5322.\r\n";
59struct upload_status {
60 size_t bytes_read;
61};
63static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
64{
65 struct upload_status *upload_ctx = (struct upload_status *)userp;
66 const char *data;
67 size_t room = size * nmemb;
68 size_t len;
70 if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) {
71 return 0;
72 }
74 data = &payload_text[upload_ctx->bytes_read];
76 len = strlen(data);
77 if(room < len)
78 len = room;
79 memcpy(ptr, data, len);
80 upload_ctx->bytes_read += len;
82 return len;
83}
85int main(void)
86{
87 CURL *curl;
89 CURLcode result = curl_global_init(CURL_GLOBAL_ALL);
90 if(result != CURLE_OK)
91 return (int)result;
93 curl = curl_easy_init();
94 if(curl) {
95 struct curl_slist *recipients = NULL;
96 struct upload_status upload_ctx = { 0 };
98 /* Set username and password */
99 curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
100 curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
102 /* This is the URL for your mailserver. Note the use of smtps:// rather
103 * than smtp:// to request an SSL based connection. */
104 curl_easy_setopt(curl, CURLOPT_URL, "smtps://mainserver.example.net");
106 /* If you want to connect to a site who is not using a certificate that is
107 * signed by one of the certs in the CA bundle you have, you can skip the
108 * verification of the server's certificate. This makes the connection
109 * A LOT LESS SECURE.
110 *
111 * If you have a CA cert for the server stored someplace else than in the
112 * default bundle, then the CURLOPT_CAPATH option might come handy for
113 * you. */
114#ifdef SKIP_PEER_VERIFICATION
115 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
116#endif
118 /* If the site you are connecting to uses a different hostname than what
119 * they have mentioned in their server certificate's commonName (or
120 * subjectAltName) fields, libcurl refuses to connect. You can skip this
121 * check, but it makes the connection insecure. */
122#ifdef SKIP_HOSTNAME_VERIFICATION
123 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
124#endif
126 /* Note that this option is not strictly required, omitting it results in
127 * libcurl sending the MAIL FROM command with empty sender data. All
128 * autoresponses should have an empty reverse-path, and should be directed
129 * to the address in the reverse-path which triggered them. Otherwise,
130 * they could cause an endless loop. See RFC 5321 Section 4.5.5 for more
131 * details.
132 */
133 curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM_MAIL);
135 /* Add two recipients, in this particular case they correspond to the
136 * To: and Cc: addressees in the header, but they could be any kind of
137 * recipient. */
138 recipients = curl_slist_append(recipients, TO_MAIL);
139 recipients = curl_slist_append(recipients, CC_MAIL);
140 curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
142 /* We are using a callback function to specify the payload (the headers
143 * and body of the message). You can use the CURLOPT_READDATA option to
144 * specify a FILE pointer to read from. */
145 curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
146 curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
147 curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
149 /* Since the traffic is encrypted, it is useful to turn on debug
150 * information within libcurl to see what is happening during the
151 * transfer */
152 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
154 /* Send the message */
155 result = curl_easy_perform(curl);
157 /* Check for errors */
158 if(result != CURLE_OK)
159 fprintf(stderr, "curl_easy_perform() failed: %s\n",
160 curl_easy_strerror(result));
162 /* Free the list of recipients */
163 curl_slist_free_all(recipients);
165 /* Always cleanup */
166 curl_easy_cleanup(curl);
167 }
169 curl_global_cleanup();
171 return (int)result;
172}
Diagnostics4 git calls · 330 ms
CallStatusSizeTime0330 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit20 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=20 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=20 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2002.6 KiB307 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=307 git.response.bytes=2623 git.response.cache=MISS git.response.duration_ms=307 git.fetch.wants=172f66b8dac7e1ca3ccf57710329809f2159a9ab git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2623 git.pkt.payload.max=2602 git.sideband.band1.bytes=2601 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e2b828ef6fcf33
- Request
- 8f859b56…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format