June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,99 @@
/*Abhishek Ghosh, 13th June 2018*/
#include <curl/curl.h>
#include <string.h>
#include <stdio.h>
#define from "<sender@duniya.com>"
#define to "<addressee@gmail.com>"
#define cc "<info@example.org>"
static const char *payload_text[] = {
"Date: Mon, 13 Jun 2018 11:30:00 +0100\r\n",
"To: " to "\r\n",
"From: " from " (Example User)\r\n",
"Cc: " cc " (Another example User)\r\n",
"Message-ID: <ecd7db36-10ab-437a-9g3a-e652b9458efd@"
"rfcpedant.example.org>\r\n",
"Subject: Sanding mail via C\r\n",
"\r\n",
"This mail is being sent by a C program.\r\n",
"\r\n",
"It connects to the GMail SMTP server, by far, the most popular mail program of all.\r\n",
"Which is also probably written in C.\r\n",
"To C or not to C..............\r\n",
"That is the question.\r\n",
NULL
};
struct upload_status {
int lines_read;
};
static size_t payload_source(void *ptr, size_t size, size_t nmemb, void *userp)
{
struct upload_status *upload_ctx = (struct upload_status *)userp;
const char *data;
if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
return 0;
}
data = payload_text[upload_ctx->lines_read];
if(data) {
size_t len = strlen(data);
memcpy(ptr, data, len);
upload_ctx->lines_read++;
return len;
}
return 0;
}
int main(void)
{
CURL *curl;
CURLcode res = CURLE_OK;
struct curl_slist *recipients = NULL;
struct upload_status upload_ctx;
upload_ctx.lines_read = 0;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
curl_easy_setopt(curl, CURLOPT_URL, "smtp://smtp.gmail.com:465");
curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem");
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from);
recipients = curl_slist_append(recipients, to);
recipients = curl_slist_append(recipients, cc);
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);
curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
curl_slist_free_all(recipients);
curl_easy_cleanup(curl);
}
return (int)res;
}

View file

@ -0,0 +1,47 @@
import javax.mail.*
import javax.mail.internet.*
public static void simpleMail(String from, String password, String to,
String subject, String body) throws Exception {
String host = "smtp.gmail.com";
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable",true);
/* mail.smtp.ssl.trust is needed in script to avoid error "Could not convert socket to TLS" */
props.setProperty("mail.smtp.ssl.trust", host);
props.put("mail.smtp.auth", true);
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", password);
props.put("mail.smtp.port", "587");
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress toAddress = new InternetAddress(to);
message.addRecipient(Message.RecipientType.TO, toAddress);
message.setSubject(subject);
message.setText(body);
Transport transport = session.getTransport("smtp");
transport.connect(host, from, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
/* Set email address sender */
String s1 = "example@gmail.com";
/* Set password sender */
String s2 = "";
/* Set email address sender */
String s3 = "example@gmail.com"
/*Call function */
simpleMail(s1, s2 , s3, "TITLE", "TEXT");

View file

@ -0,0 +1,24 @@
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Network.Mail.SMTP
( Address(..)
, htmlPart
, plainTextPart
, sendMailWithLogin'
, simpleMail
)
main :: IO ()
main =
sendMailWithLogin' "smtp.example.com" 25 "user" "password" $
simpleMail
(Address (Just "From Example") "from@example.com")
[Address (Just "To Example") "to@example.com"]
[] -- CC
[] -- BCC
"Subject"
[ plainTextPart "This is plain text."
, htmlPart "<h1>Title</h1><p>This is HTML.</p>"
]

View file

@ -0,0 +1,7 @@
procedure main(args)
mail := open("mailto:"||args[1], "m", "Subject : "||args[2],
"X-Note: automatically send by Unicon") |
stop("Cannot send mail to ",args[1])
every write(mail , !&input)
close (mail)
end

View file

@ -0,0 +1,18 @@
using SMTPClient
addbrackets(s) = replace(s, r"^\s*([^\<\>]+)\s*$", s"<\1>")
function wrapRFC5322(from, to, subject, msg)
timestr = Libc.strftime("%a, %d %b %Y %H:%M:%S %z", time())
IOBuffer("Date: $timestr\nTo: $to\nFrom: $from\nSubject: $subject\n\n$msg")
end
function sendemail(from, to, subject, messagebody, serverandport;
cc=[], user="", password="", isSSL=true, blocking=true)
opt = SendOptions(blocking=blocking, isSSL=isSSL, username=user, passwd=password)
send(serverandport, map(s -> addbrackets(s), vcat(to, cc)), addbrackets(from),
wrapRFC5322(addbrackets(from), addbrackets(to), subject, messagebody), opt)
end
sendemail("to@example.com", "from@example.com", "TEST", "hello there test message text here", "smtps://smtp.gmail.com",
user="from@example.com", password="example.com")

View file

@ -1,3 +1,4 @@
load "stdlib.ring"
See "Send email..." + nl
sendemail("smtp://smtp.gmail.com",
"calmosoft@gmail.com",