Send email: Difference between revisions

→‎{{header|Perl 6}}: Add code to actually (theoretically) send the email
m (→‎{{header|Python}}: Sub-headers)
(→‎{{header|Perl 6}}: Add code to actually (theoretically) send the email)
Line 1,249:
 
=={{header|Perl 6}}==
<lang perl6>#use ReferenceEmail: https://github.com/retupmoca/p6-Email-Simple;
use Email::Simple;
 
my $emlto = Email::Simple.new($raw-'mail-text)@example.com';
my $from = 'me@example.com';
say $eml.body;
my $subject = 'test';
my $body = 'This is a test.';
 
my $newemail = Email::Simple.create(header => [['To', 'mail@example.com'],
:header[['To', $to], ['From', $from], ['Subject', $subject]],
['From', 'me@example.com'],
:body($body)
['Subject', 'test']],
);
body => 'This is a test.');
 
say ~$new;</lang>
say ~$email;
 
# Note that the following will fail without an actual smtp server that
# will accept anonymous emails on port 25 (Not very common anymore).
# Most public email servers now require authentication and encryption.
 
my $smtp-server = 'smtp.example.com';
my $smtp-port = 25;
 
await IO::Socket::Async.connect($smtp-server, $smtp-port).then(
-> $smtp {
if $smtp.status {
given $smtp.result {
react {
whenever .Supply() -> $response {
if $response ~~ /^220/ {
.print( join "\r\n",
body =>"EHLO 'This is a test.');$smtp-server",
"MAIL FROM:<{$email.from}>",
"RCPT TO:<{$email.to}>",
['Subject'"DATA", 'test']]$email.body,
['From.', 'me@example.com'],
)
}
elsif $response ~~ /^250/ {
.print("QUIT\r\n");
done
}
else {
say "Send email failed with: $response";
done
}
}
.close
}
}
}
}
say ~$new;)</lang>
 
=={{header|PHP}}==
10,327

edits