Send email: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 274: Line 274:
return (int)res;
return (int)res;
}
</lang>

=={{header|C sharp|C#}}==
{{works with|Mono|1.2}}
{{works with|Visual C sharp|Visual C#|2003}}
<lang csharp>
static void Main(string[] args)
{
//First of all construct the SMTP client

SmtpClient SMTP = new SmtpClient("smtp.gmail.com", 587); //I have provided the URI and port for GMail, replace with your providers SMTP details
SMTP.EnableSsl = true; //Required for gmail, may not for your provider, if your provider does not require it then use false.
SMTP.DeliveryMethod = SmtpDeliveryMethod.Network;
SMTP.Credentials = new NetworkCredential("YourUserName", "YourPassword");
MailMessage Mail = new MailMessage("yourEmail@address.com", "theirEmail@address.com");


//Then we construct the message

Mail.Subject = "Important Message";
Mail.Body = "Hello over there"; //The body contains the string for your email
//using "Mail.IsBodyHtml = true;" you can put an HTML page in your message body

//Then we use the SMTP client to send the message

SMTP.Send(Mail);

Console.WriteLine("Message Sent");
}
}
</lang>
</lang>
Line 336: Line 365:


This version does not do authentication. However, the login() method can accept a username and password for authentication. Also, newer versions of POCO provide SecureSMTPClientSession, for doing STARTTLS.
This version does not do authentication. However, the login() method can accept a username and password for authentication. Also, newer versions of POCO provide SecureSMTPClientSession, for doing STARTTLS.

=={{header|C sharp|C#}}==
{{works with|Mono|1.2}}
{{works with|Visual C sharp|Visual C#|2003}}
<lang csharp>
static void Main(string[] args)
{
//First of all construct the SMTP client

SmtpClient SMTP = new SmtpClient("smtp.gmail.com", 587); //I have provided the URI and port for GMail, replace with your providers SMTP details
SMTP.EnableSsl = true; //Required for gmail, may not for your provider, if your provider does not require it then use false.
SMTP.DeliveryMethod = SmtpDeliveryMethod.Network;
SMTP.Credentials = new NetworkCredential("YourUserName", "YourPassword");
MailMessage Mail = new MailMessage("yourEmail@address.com", "theirEmail@address.com");


//Then we construct the message

Mail.Subject = "Important Message";
Mail.Body = "Hello over there"; //The body contains the string for your email
//using "Mail.IsBodyHtml = true;" you can put an HTML page in your message body

//Then we use the SMTP client to send the message

SMTP.Send(Mail);

Console.WriteLine("Message Sent");
}
</lang>


=={{header|Clojure}}==
=={{header|Clojure}}==
Line 991: Line 991:
end
end
</lang>
</lang>

=={{header|Lingo}}==
=={{header|Lingo}}==
Lingo has no built-in support for sending email. But this can be achieved e.g. by using Shell Xtra and one of the available command-line SMTP clients.
Lingo has no built-in support for sending email. But this can be achieved e.g. by using Shell Xtra and one of the available command-line SMTP clients.
Line 1,125: Line 1,125:
"UserName"</lang>
"UserName"</lang>
Possible options for EncryptionProtocol are: "SSL","StartTLS" and "TLS". This function should work fine on all the OS's Mathematica runs, which includes the largest 3: Windows, Linux, Mac OSX.
Possible options for EncryptionProtocol are: "SSL","StartTLS" and "TLS". This function should work fine on all the OS's Mathematica runs, which includes the largest 3: Windows, Linux, Mac OSX.



=={{header|NewLISP}}==
=={{header|NewLISP}}==
Line 1,247: Line 1,246:
"very important subject",
"very important subject",
"Body text\n");</lang>
"Body text\n");</lang>

=={{header|Perl 6}}==
<lang perl6>use Email::Simple;

my $to = 'mail@example.com';
my $from = 'me@example.com';
my $subject = 'test';
my $body = 'This is a test.';

my $email = Email::Simple.create(
:header[['To', $to], ['From', $from], ['Subject', $subject]],
:body($body)
);

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",
"EHLO $smtp-server",
"MAIL FROM:<{$email.from}>",
"RCPT TO:<{$email.to}>",
"DATA", $email.body,
'.', ''
)
}
elsif $response ~~ /^250/ {
.print("QUIT\r\n");
done
}
else {
say "Send email failed with: $response";
done
}
}
.close
}
}
}
}
)</lang>


=={{header|Phix}}==
=={{header|Phix}}==
Line 1,542: Line 1,488:
'("Hello World!"))
'("Hello World!"))
</lang>
</lang>

=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>use Email::Simple;

my $to = 'mail@example.com';
my $from = 'me@example.com';
my $subject = 'test';
my $body = 'This is a test.';

my $email = Email::Simple.create(
:header[['To', $to], ['From', $from], ['Subject', $subject]],
:body($body)
);

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",
"EHLO $smtp-server",
"MAIL FROM:<{$email.from}>",
"RCPT TO:<{$email.to}>",
"DATA", $email.body,
'.', ''
)
}
elsif $response ~~ /^250/ {
.print("QUIT\r\n");
done
}
else {
say "Send email failed with: $response";
done
}
}
.close
}
}
}
}
)</lang>


=={{header|REBOL}}==
=={{header|REBOL}}==