Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
13
Task/Send-email/Emacs-Lisp/send-email.l
Normal file
13
Task/Send-email/Emacs-Lisp/send-email.l
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
(defun my-send-email (from to cc subject text)
|
||||
(with-temp-buffer
|
||||
(insert "From: " from "\n"
|
||||
"To: " to "\n"
|
||||
"Cc: " cc "\n"
|
||||
"Subject: " subject "\n"
|
||||
mail-header-separator "\n"
|
||||
text)
|
||||
(funcall send-mail-function)))
|
||||
|
||||
(my-send-email "from@example.com" "to@example.com" ""
|
||||
"very important"
|
||||
"body\ntext\n")
|
||||
161
Task/Send-email/Go/send-email.go
Normal file
161
Task/Send-email/Go/send-email.go
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/smtp"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
From string
|
||||
To []string
|
||||
Cc []string
|
||||
Subject string
|
||||
Content string
|
||||
}
|
||||
|
||||
func (m Message) Bytes() (r []byte) {
|
||||
to := strings.Join(m.To, ",")
|
||||
cc := strings.Join(m.Cc, ",")
|
||||
|
||||
r = append(r, []byte("From: "+m.From+"\n")...)
|
||||
r = append(r, []byte("To: "+to+"\n")...)
|
||||
r = append(r, []byte("Cc: "+cc+"\n")...)
|
||||
r = append(r, []byte("Subject: "+m.Subject+"\n\n")...)
|
||||
r = append(r, []byte(m.Content)...)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (m Message) Send(host string, port int, user, pass string) (err error) {
|
||||
err = check(host, user, pass)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = smtp.SendMail(fmt.Sprintf("%v:%v", host, port),
|
||||
smtp.PlainAuth("", user, pass, host),
|
||||
m.From,
|
||||
m.To,
|
||||
m.Bytes(),
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func check(host, user, pass string) error {
|
||||
if host == "" {
|
||||
return errors.New("Bad host")
|
||||
}
|
||||
if user == "" {
|
||||
return errors.New("Bad username")
|
||||
}
|
||||
if pass == "" {
|
||||
return errors.New("Bad password")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
var flags struct {
|
||||
host string
|
||||
port int
|
||||
user string
|
||||
pass string
|
||||
}
|
||||
flag.StringVar(&flags.host, "host", "", "SMTP server to connect to")
|
||||
flag.IntVar(&flags.port, "port", 587, "Port to connect to SMTP server on")
|
||||
flag.StringVar(&flags.user, "user", "", "Username to authenticate with")
|
||||
flag.StringVar(&flags.pass, "pass", "", "Password to authenticate with")
|
||||
flag.Parse()
|
||||
|
||||
err := check(flags.host, flags.user, flags.pass)
|
||||
if err != nil {
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
bufin := bufio.NewReader(os.Stdin)
|
||||
|
||||
fmt.Printf("From: ")
|
||||
from, err := bufin.ReadString('\n')
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
from = strings.Trim(from, " \t\n\r")
|
||||
|
||||
var to []string
|
||||
for {
|
||||
fmt.Printf("To (Blank to finish): ")
|
||||
tmp, err := bufin.ReadString('\n')
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
tmp = strings.Trim(tmp, " \t\n\r")
|
||||
|
||||
if tmp == "" {
|
||||
break
|
||||
}
|
||||
|
||||
to = append(to, tmp)
|
||||
}
|
||||
|
||||
var cc []string
|
||||
for {
|
||||
fmt.Printf("Cc (Blank to finish): ")
|
||||
tmp, err := bufin.ReadString('\n')
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
tmp = strings.Trim(tmp, " \t\n\r")
|
||||
|
||||
if tmp == "" {
|
||||
break
|
||||
}
|
||||
|
||||
cc = append(cc, tmp)
|
||||
}
|
||||
|
||||
fmt.Printf("Subject: ")
|
||||
subject, err := bufin.ReadString('\n')
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
subject = strings.Trim(subject, " \t\n\r")
|
||||
|
||||
fmt.Printf("Content (Until EOF):\n")
|
||||
content, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
content = bytes.Trim(content, " \t\n\r")
|
||||
|
||||
m := Message{
|
||||
From: from,
|
||||
To: to,
|
||||
Cc: cc,
|
||||
Subject: subject,
|
||||
Content: string(content),
|
||||
}
|
||||
|
||||
fmt.Printf("\nSending message...\n")
|
||||
err = m.Send(flags.host, flags.port, flags.user, flags.pass)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("Message sent.\n")
|
||||
}
|
||||
47
Task/Send-email/Groovy/send-email-1.groovy
Normal file
47
Task/Send-email/Groovy/send-email-1.groovy
Normal 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");
|
||||
7
Task/Send-email/Groovy/send-email-2.groovy
Normal file
7
Task/Send-email/Groovy/send-email-2.groovy
Normal 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
|
||||
22
Task/Send-email/Perl/send-email-4.pl
Normal file
22
Task/Send-email/Perl/send-email-4.pl
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use strict;
|
||||
use LWP::UserAgent;
|
||||
use HTTP::Request;
|
||||
|
||||
sub send_email {
|
||||
my ($from, $to, $cc, $subject, $text) = @_;
|
||||
|
||||
my $ua = LWP::UserAgent->new;
|
||||
my $req = HTTP::Request->new (POST => "mailto:$to",
|
||||
[ From => $from,
|
||||
Cc => $cc,
|
||||
Subject => $subject ],
|
||||
$text);
|
||||
my $resp = $ua->request($req);
|
||||
if (! $resp->is_success) {
|
||||
print $resp->status_line,"\n";
|
||||
}
|
||||
}
|
||||
|
||||
send_email('from-me@example.com', 'to-foo@example.com', '',
|
||||
"very important subject",
|
||||
"Body text\n");
|
||||
20
Task/Send-email/VBScript/send-email.vb
Normal file
20
Task/Send-email/VBScript/send-email.vb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
Function send_mail(from,recipient,cc,subject,message)
|
||||
With CreateObject("CDO.Message")
|
||||
.From = from
|
||||
.To = recipient
|
||||
.CC = cc
|
||||
.Subject = subject
|
||||
.Textbody = message
|
||||
.Configuration.Fields.Item _
|
||||
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
|
||||
.Configuration.Fields.Item _
|
||||
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
|
||||
"mystmpserver"
|
||||
.Configuration.Fields.Item _
|
||||
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
|
||||
.Configuration.Fields.Update
|
||||
.Send
|
||||
End With
|
||||
End Function
|
||||
|
||||
Call send_mail("Alerts@alerts.org","jkspeed@jkspeed.org","","Test Email","this is a test message")
|
||||
Loading…
Add table
Add a link
Reference in a new issue