Send email: Difference between revisions
Content added Content deleted
m (→{{header|Diego}}: syntax) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 15: | Line 15: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
{{libheader|AWS}} |
{{libheader|AWS}} |
||
< |
<syntaxhighlight lang="ada">with AWS.SMTP, AWS.SMTP.Client, AWS.SMTP.Authentication.Plain; |
||
with Ada.Text_IO; |
with Ada.Text_IO; |
||
use Ada, AWS; |
use Ada, AWS; |
||
Line 42: | Line 42: | ||
end if; |
end if; |
||
end Sendmail; |
end Sendmail; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
ahk [http://www.autohotkey.com%2Fforum%2Ftopic39797.html discussion] |
ahk [http://www.autohotkey.com%2Fforum%2Ftopic39797.html discussion] |
||
{{libheader | COM.ahk}} |
{{libheader | COM.ahk}} |
||
< |
<syntaxhighlight lang="autohotkey">sSubject:= "greeting" |
||
sText := "hello" |
sText := "hello" |
||
sFrom := "ahk@rosettacode" |
sFrom := "ahk@rosettacode" |
||
Line 83: | Line 83: | ||
COM_Release(pmsg) |
COM_Release(pmsg) |
||
COM_Term() |
COM_Term() |
||
#Include COM.ahk</ |
#Include COM.ahk</syntaxhighlight> |
||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
{{works with|BBC BASIC for Windows}} |
{{works with|BBC BASIC for Windows}} |
||
< |
<syntaxhighlight lang="bbcbasic"> INSTALL @lib$+"SOCKLIB" |
||
Server$ = "smtp.gmail.com" |
Server$ = "smtp.gmail.com" |
||
Line 171: | Line 171: | ||
WHILE FN_readlinesocket(skt%, 10, reply$) > 0 : ENDWHILE |
WHILE FN_readlinesocket(skt%, 10, reply$) > 0 : ENDWHILE |
||
ENDPROC |
ENDPROC |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|C}}== |
=={{header|C}}== |
||
Sends mail via the GMail SMTP server, requires [https://curl.haxx.se/libcurl/ libcurl] |
Sends mail via the GMail SMTP server, requires [https://curl.haxx.se/libcurl/ libcurl] |
||
{{libheader|libcurl}} |
{{libheader|libcurl}} |
||
<syntaxhighlight lang="c"> |
|||
<lang C> |
|||
#include <curl/curl.h> |
#include <curl/curl.h> |
||
Line 275: | Line 275: | ||
return (int)res; |
return (int)res; |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
{{works with|Mono|1.2}} |
{{works with|Mono|1.2}} |
||
{{works with|Visual C sharp|Visual C#|2003}} |
{{works with|Visual C sharp|Visual C#|2003}} |
||
< |
<syntaxhighlight lang="csharp"> |
||
static void Main(string[] args) |
static void Main(string[] args) |
||
{ |
{ |
||
Line 304: | Line 304: | ||
Console.WriteLine("Message Sent"); |
Console.WriteLine("Message Sent"); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|C++}}== |
=={{header|C++}}== |
||
Line 311: | Line 311: | ||
{{works with|POCO|1.3.6}} |
{{works with|POCO|1.3.6}} |
||
< |
<syntaxhighlight lang="cpp">// on Ubuntu: sudo apt-get install libpoco-dev |
||
// or see http://pocoproject.org/ |
// or see http://pocoproject.org/ |
||
// compile with: g++ -Wall -O3 send-mail-cxx.C -lPocoNet -lPocoFoundation |
// compile with: g++ -Wall -O3 send-mail-cxx.C -lPocoNet -lPocoFoundation |
||
Line 356: | Line 356: | ||
return EXIT_SUCCESS; |
return EXIT_SUCCESS; |
||
}</ |
}</syntaxhighlight> |
||
When run literally as above, should print: |
When run literally as above, should print: |
||
Line 370: | Line 370: | ||
[https://github.com/drewr/postal Postal] wraps JavaMail to make sending emails simple and platform independent. |
[https://github.com/drewr/postal Postal] wraps JavaMail to make sending emails simple and platform independent. |
||
< |
<syntaxhighlight lang="clojure">(require '[postal.core :refer [send-message]]) |
||
(send-message {:host "smtp.gmail.com" |
(send-message {:host "smtp.gmail.com" |
||
Line 380: | Line 380: | ||
:cc ["bob@builder.com" "dora@explorer.com"] |
:cc ["bob@builder.com" "dora@explorer.com"] |
||
:subject "Yo" |
:subject "Yo" |
||
:body "Testing."})</ |
:body "Testing."})</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 387: | Line 387: | ||
=={{header|D}}== |
=={{header|D}}== |
||
Requires the libcurl library to be installed on the system. |
Requires the libcurl library to be installed on the system. |
||
< |
<syntaxhighlight lang="d">void main() { |
||
import std.net.curl; |
import std.net.curl; |
||
Line 396: | Line 396: | ||
s.message = "Subject:test\n\nExample Message"; |
s.message = "Subject:test\n\nExample Message"; |
||
s.perform; |
s.perform; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
<syntaxhighlight lang="delphi"> |
|||
<lang Delphi> |
|||
procedure SendEmail; |
procedure SendEmail; |
||
var |
var |
||
Line 433: | Line 433: | ||
end; |
end; |
||
end; |
end; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Diego}}== |
=={{header|Diego}}== |
||
This <code>instruct</code>ion instructs a thing in the mist to send an email. It understands that the found <code>thing</code> will have email knowledge (similar to libraries in other languages). If the caller does not have email knowledge, the callee will train the caller on first request. It is at the discretion of the callee to adjust, delay or not send the email. |
This <code>instruct</code>ion instructs a thing in the mist to send an email. It understands that the found <code>thing</code> will have email knowledge (similar to libraries in other languages). If the caller does not have email knowledge, the callee will train the caller on first request. It is at the discretion of the callee to adjust, delay or not send the email. |
||
< |
<syntaxhighlight lang="diego">begin_instruct(Send email)_param({str} from, to, cc, subject, msg, {html}, htmlmsg)_opt({cred}, login)_ns(rosettacode); |
||
set_thread(linger); |
set_thread(linger); |
||
find_thing()_first()_email() |
find_thing()_first()_email() |
||
Line 468: | Line 468: | ||
_me(); |
_me(); |
||
reset_namespace();</ |
reset_namespace();</syntaxhighlight> |
||
=={{header|Emacs Lisp}}== |
=={{header|Emacs Lisp}}== |
||
Line 474: | Line 474: | ||
Variable <code>send-mail-function</code> holds a function for sending a message from the current buffer. The user or sysadmin is expected to set that variable to a preferred method (<code>sendmail</code>, SMTP, etc). The default queries the user for initial setup. |
Variable <code>send-mail-function</code> holds a function for sending a message from the current buffer. The user or sysadmin is expected to set that variable to a preferred method (<code>sendmail</code>, SMTP, etc). The default queries the user for initial setup. |
||
< |
<syntaxhighlight lang="lisp">(defun my-send-email (from to cc subject text) |
||
(with-temp-buffer |
(with-temp-buffer |
||
(insert "From: " from "\n" |
(insert "From: " from "\n" |
||
Line 486: | Line 486: | ||
(my-send-email "from@example.com" "to@example.com" "" |
(my-send-email "from@example.com" "to@example.com" "" |
||
"very important" |
"very important" |
||
"body\ntext\n")</ |
"body\ntext\n")</syntaxhighlight> |
||
The buffer filling here pays no attention to charset or possible special characters in the fields or text. |
The buffer filling here pays no attention to charset or possible special characters in the fields or text. |
||
Line 495: | Line 495: | ||
This one uses the build-in SMTP vocabulary. Note that 'to' and 'cc' need to be arrays of strings containing an email address. |
This one uses the build-in SMTP vocabulary. Note that 'to' and 'cc' need to be arrays of strings containing an email address. |
||
<syntaxhighlight lang="factor"> |
|||
<lang Factor> |
|||
USING: accessors io.sockets locals namespaces smtp ; |
USING: accessors io.sockets locals namespaces smtp ; |
||
IN: scratchpad |
IN: scratchpad |
||
Line 503: | Line 503: | ||
"my.gmail.address@gmail.com" "qwertyuiasdfghjk" <plain-auth> |
"my.gmail.address@gmail.com" "qwertyuiasdfghjk" <plain-auth> |
||
>>auth \ smtp-config set-global <email> f >>from t >>to |
>>auth \ smtp-config set-global <email> f >>from t >>to |
||
c >>cc s >>subject b >>body send-email ;</ |
c >>cc s >>subject b >>body send-email ;</syntaxhighlight> |
||
=={{header|Fantom}}== |
=={{header|Fantom}}== |
||
Line 509: | Line 509: | ||
There's a built-in Email library, which will work on the JVM, CLR and Javascript runtimes. Errors are thrown if there is a problem with the protocol or the network. |
There's a built-in Email library, which will work on the JVM, CLR and Javascript runtimes. Errors are thrown if there is a problem with the protocol or the network. |
||
< |
<syntaxhighlight lang="fantom"> |
||
using email |
using email |
||
Line 542: | Line 542: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
Line 548: | Line 548: | ||
Using Outlook COM server. Before compiling the program, it's necessary to use the '''[https://software.intel.com/en-us/node/535422 Intel Fortran Module Wizard]''' from the Visual Studio editor, to generate a Fortran module for the Microsoft Outlook Object Library. The following program has to be linked with this module (msoutl). |
Using Outlook COM server. Before compiling the program, it's necessary to use the '''[https://software.intel.com/en-us/node/535422 Intel Fortran Module Wizard]''' from the Visual Studio editor, to generate a Fortran module for the Microsoft Outlook Object Library. The following program has to be linked with this module (msoutl). |
||
< |
<syntaxhighlight lang="fortran">program sendmail |
||
use ifcom |
use ifcom |
||
use msoutl |
use msoutl |
||
Line 563: | Line 563: | ||
call $Application_Quit(app, status) |
call $Application_Quit(app, status) |
||
call comuninitialize() |
call comuninitialize() |
||
end program</ |
end program</syntaxhighlight> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
Line 570: | Line 570: | ||
Supports TLS connections. |
Supports TLS connections. |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 730: | Line 730: | ||
fmt.Printf("Message sent.\n") |
fmt.Printf("Message sent.\n") |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
From [http://www.jedox.com/en/send-email-using-javamail-groovy-script/] we can get email solution for Groovy |
From [http://www.jedox.com/en/send-email-using-javamail-groovy-script/] we can get email solution for Groovy |
||
<syntaxhighlight lang="groovy"> |
|||
<lang Groovy> |
|||
import javax.mail.* |
import javax.mail.* |
||
import javax.mail.internet.* |
import javax.mail.internet.* |
||
Line 782: | Line 782: | ||
/*Call function */ |
/*Call function */ |
||
simpleMail(s1, s2 , s3, "TITLE", "TEXT"); |
simpleMail(s1, s2 , s3, "TITLE", "TEXT"); |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
Line 788: | Line 788: | ||
Example using [https://hackage.haskell.org/package/smtp-mail <tt>smtp-mail</tt>] package: |
Example using [https://hackage.haskell.org/package/smtp-mail <tt>smtp-mail</tt>] package: |
||
< |
<syntaxhighlight lang="haskell">{-# LANGUAGE OverloadedStrings #-} |
||
module Main (main) where |
module Main (main) where |
||
Line 811: | Line 811: | ||
[ plainTextPart "This is plain text." |
[ plainTextPart "This is plain text." |
||
, htmlPart "<h1>Title</h1><p>This is HTML.</p>" |
, htmlPart "<h1>Title</h1><p>This is HTML.</p>" |
||
]</ |
]</syntaxhighlight> |
||
==Icon and {{header|Unicon}}== |
==Icon and {{header|Unicon}}== |
||
A Unicon-specific solution is: |
A Unicon-specific solution is: |
||
< |
<syntaxhighlight lang="unicon">procedure main(args) |
||
mail := open("mailto:"||args[1], "m", "Subject : "||args[2], |
mail := open("mailto:"||args[1], "m", "Subject : "||args[2], |
||
"X-Note: automatically send by Unicon") | |
"X-Note: automatically send by Unicon") | |
||
Line 822: | Line 822: | ||
every write(mail , !&input) |
every write(mail , !&input) |
||
close (mail) |
close (mail) |
||
end</ |
end</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java5">import java.util.Properties; |
||
import javax.mail.MessagingException; |
import javax.mail.MessagingException; |
||
Line 881: | Line 881: | ||
Transport.send(message); |
Transport.send(message); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia"> |
||
using SMTPClient |
using SMTPClient |
||
Line 903: | Line 903: | ||
sendemail("to@example.com", "from@example.com", "TEST", "hello there test message text here", "smtps://smtp.gmail.com", |
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") |
user="from@example.com", password="example.com") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
To compile and run this program 'javax.mail.jar' will need to be present on your system and added to your classpath. Also if you're using the Google SMTP Server then, as well as requiring a gmail account, you'll probably need to temporarily turn on 'access for less secure apps' to prevent it from being blocked. |
To compile and run this program 'javax.mail.jar' will need to be present on your system and added to your classpath. Also if you're using the Google SMTP Server then, as well as requiring a gmail account, you'll probably need to temporarily turn on 'access for less secure apps' to prevent it from being blocked. |
||
< |
<syntaxhighlight lang="scala">// version 1.1.4-3 |
||
import java.util.Properties |
import java.util.Properties |
||
Line 957: | Line 957: | ||
val password = "secret" |
val password = "secret" |
||
sendEmail(user, tos, ccs, title, body, password) |
sendEmail(user, tos, ccs, title, body, password) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Lasso}}== |
=={{header|Lasso}}== |
||
This example leverages Lasso's built in Email_Send method. |
This example leverages Lasso's built in Email_Send method. |
||
< |
<syntaxhighlight lang="lasso">// with a lot of unneeded params. |
||
// sends plain text and html in same email |
// sends plain text and html in same email |
||
// simple usage is below |
// simple usage is below |
||
Line 995: | Line 995: | ||
-body = 'Lasso is awesome, you should try it!' |
-body = 'Lasso is awesome, you should try it!' |
||
) |
) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Liberty BASIC}}== |
=={{header|Liberty BASIC}}== |
||
This program requires sendemail.exe and sendemail.pl in the same directory, available free from Caspian's SendEmail Site. |
This program requires sendemail.exe and sendemail.pl in the same directory, available free from Caspian's SendEmail Site. |
||
<syntaxhighlight lang="lb"> |
|||
<lang lb> |
|||
text$ = "This is a simple text message." |
text$ = "This is a simple text message." |
||
Line 1,025: | Line 1,025: | ||
end |
end |
||
</syntaxhighlight> |
|||
</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. |
||
{{libheader|Shell Xtra}} |
{{libheader|Shell Xtra}} |
||
< |
<syntaxhighlight lang="lingo">---------------------------------------- |
||
-- Sends email via SMTP using senditquiet.exe (15 KB) |
-- Sends email via SMTP using senditquiet.exe (15 KB) |
||
-- @param {string} fromAddr |
-- @param {string} fromAddr |
||
Line 1,082: | Line 1,082: | ||
res = sx.shell_cmd(cmd) |
res = sx.shell_cmd(cmd) |
||
return not(res contains "ERROR") |
return not(res contains "ERROR") |
||
end</ |
end</syntaxhighlight> |
||
=={{header|LiveCode}}== |
=={{header|LiveCode}}== |
||
LiveCode provides a built-in method that will create an email in the registered mailto: handler on supported OS. |
LiveCode provides a built-in method that will create an email in the registered mailto: handler on supported OS. |
||
< |
<syntaxhighlight lang="livecode">revMail "help@example.com",,"Help!",field "Message"</syntaxhighlight> |
||
To create and ''send'' an email in LiveCode requires coding your own smtp client, or using one of a couple of 3rd party stacks. |
To create and ''send'' an email in LiveCode requires coding your own smtp client, or using one of a couple of 3rd party stacks. |
||
=={{header|LotusScript}}== |
=={{header|LotusScript}}== |
||
< |
<syntaxhighlight lang="lotusscript">Dim session As New NotesSession |
||
Dim db As NotesDatabase |
Dim db As NotesDatabase |
||
Dim doc As NotesDocument |
Dim doc As NotesDocument |
||
Line 1,099: | Line 1,099: | ||
doc.SendTo = "John Doe" |
doc.SendTo = "John Doe" |
||
doc.Subject = "Subject of this mail" |
doc.Subject = "Subject of this mail" |
||
Call doc.Send( False )</ |
Call doc.Send( False )</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
Line 1,105: | Line 1,105: | ||
Using [http://w3.impa.br/~diego/software/luasocket/smtp.html LuaSocket's SMTP module] (from the documentation on that page): |
Using [http://w3.impa.br/~diego/software/luasocket/smtp.html LuaSocket's SMTP module] (from the documentation on that page): |
||
< |
<syntaxhighlight lang="lua">-- load the smtp support |
||
local smtp = require("socket.smtp") |
local smtp = require("socket.smtp") |
||
Line 1,136: | Line 1,136: | ||
source = smtp.message(mesgt) |
source = smtp.message(mesgt) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
Mathematica has the built-in function SendMail, example: |
Mathematica has the built-in function SendMail, example: |
||
< |
<syntaxhighlight lang="mathematica">SendMail["From" -> "from@email.com", "To" -> "to@email.com", |
||
"Subject" -> "Sending Email from Mathematica", "Body" -> "Hello world!", |
"Subject" -> "Sending Email from Mathematica", "Body" -> "Hello world!", |
||
"Server" -> "smtp.email.com"]</ |
"Server" -> "smtp.email.com"]</syntaxhighlight> |
||
The following options can be specified: |
The following options can be specified: |
||
<syntaxhighlight lang="mathematica">"To" |
|||
<lang Mathematica>"To" |
|||
"Cc" |
"Cc" |
||
"Bcc" |
"Bcc" |
||
Line 1,158: | Line 1,158: | ||
"ReplyTo" |
"ReplyTo" |
||
"ServerAuthentication" |
"ServerAuthentication" |
||
"UserName"</ |
"UserName"</syntaxhighlight> |
||
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}}== |
||
* using library smtp.lsp |
* using library smtp.lsp |
||
< |
<syntaxhighlight lang="newlisp">(module "smtp.lsp") |
||
(SMTP:send-mail "user@asite.com" "somebody@isp.com" "Greetings" "How are you today? - john doe -" "smtp.asite.com" "user" "password")</ |
(SMTP:send-mail "user@asite.com" "somebody@isp.com" "Greetings" "How are you today? - john doe -" "smtp.asite.com" "user" "password")</syntaxhighlight> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
Compile with <code>nim c -d:ssl mail</code> |
Compile with <code>nim c -d:ssl mail</code> |
||
< |
<syntaxhighlight lang="nim">import smtp |
||
proc sendMail(fromAddr: string; toAddrs, ccAddrs: seq[string]; |
proc sendMail(fromAddr: string; toAddrs, ccAddrs: seq[string]; |
||
Line 1,185: | Line 1,185: | ||
message = "Nim says hi!\nAnd bye again!", |
message = "Nim says hi!\nAnd bye again!", |
||
login = "nim@gmail.com", |
login = "nim@gmail.com", |
||
password = "XXXXXX")</ |
password = "XXXXXX")</syntaxhighlight> |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
* using the library [http://www.linux-nantes.org/~fmonnier/OCaml/smtp-mail/ smtp-mail-0.1.3] |
* using the library [http://www.linux-nantes.org/~fmonnier/OCaml/smtp-mail/ smtp-mail-0.1.3] |
||
< |
<syntaxhighlight lang="ocaml">let h = Smtp.connect "smtp.gmail.fr";; |
||
Smtp.helo h "hostname";; |
Smtp.helo h "hostname";; |
||
Smtp.mail h "<john.smith@example.com>";; |
Smtp.mail h "<john.smith@example.com>";; |
||
Line 1,199: | Line 1,199: | ||
let email_msg = "Happy Birthday";; |
let email_msg = "Happy Birthday";; |
||
Smtp.data h (email_header ^ "\r\n\r\n" ^ email_msg);; |
Smtp.data h (email_header ^ "\r\n\r\n" ^ email_msg);; |
||
Smtp.quit h;;</ |
Smtp.quit h;;</syntaxhighlight> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
This subroutine throws an appropriate error if it fails to connect to the server or authenticate. It should work on any platform Perl does. |
This subroutine throws an appropriate error if it fails to connect to the server or authenticate. It should work on any platform Perl does. |
||
< |
<syntaxhighlight lang="perl">use Net::SMTP; |
||
use Authen::SASL; |
use Authen::SASL; |
||
# Net::SMTP's 'auth' method needs Authen::SASL to work, but |
# Net::SMTP's 'auth' method needs Authen::SASL to work, but |
||
Line 1,236: | Line 1,236: | ||
$smtp->dataend; |
$smtp->dataend; |
||
return 1;}</ |
return 1;}</syntaxhighlight> |
||
An example call: |
An example call: |
||
< |
<syntaxhighlight lang="perl">send_email |
||
from => 'A. T. Tappman', |
from => 'A. T. Tappman', |
||
to => ['suchandsuch@example.com', 'soandso@example.org'], |
to => ['suchandsuch@example.com', 'soandso@example.org'], |
||
Line 1,248: | Line 1,248: | ||
host => 'smtp.example.com:587', |
host => 'smtp.example.com:587', |
||
user => 'tappman@example.com', |
user => 'tappman@example.com', |
||
password => 'yossarian';</ |
password => 'yossarian';</syntaxhighlight> |
||
If the <code>host</code> parameter is omitted, <code>send_email</code> falls back on the <code>SMTP_Hosts</code> defined in <code>Net::Config</code>. Hence, only two arguments are strictly necessary: |
If the <code>host</code> parameter is omitted, <code>send_email</code> falls back on the <code>SMTP_Hosts</code> defined in <code>Net::Config</code>. Hence, only two arguments are strictly necessary: |
||
< |
<syntaxhighlight lang="perl">send_email |
||
to => 'suchandsuch@example.com', |
to => 'suchandsuch@example.com', |
||
user => 'tappman@example.com';</ |
user => 'tappman@example.com';</syntaxhighlight> |
||
{{libheader|LWP}} |
{{libheader|LWP}} |
||
Line 1,260: | Line 1,260: | ||
LWP can send email by a POST to a <code>mailto:</code> URL. The message is given as a HTTP request. This is mainly of interest for treating different types of URLs in a common way. LWP sends merely by running the <code>sendmail</code> program, or on MacOS classic by SMTP (to <code>SMTPHOSTS</code> environment variable). For reference, the <code>$ua->post()</code> method does not suit since it constructs a message as MIME "form data". |
LWP can send email by a POST to a <code>mailto:</code> URL. The message is given as a HTTP request. This is mainly of interest for treating different types of URLs in a common way. LWP sends merely by running the <code>sendmail</code> program, or on MacOS classic by SMTP (to <code>SMTPHOSTS</code> environment variable). For reference, the <code>$ua->post()</code> method does not suit since it constructs a message as MIME "form data". |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use LWP::UserAgent; |
use LWP::UserAgent; |
||
use HTTP::Request; |
use HTTP::Request; |
||
Line 1,281: | Line 1,281: | ||
send_email('from-me@example.com', 'to-foo@example.com', '', |
send_email('from-me@example.com', 'to-foo@example.com', '', |
||
"very important subject", |
"very important subject", |
||
"Body text\n");</ |
"Body text\n");</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 1,288: | Line 1,288: | ||
Obviously, USER/PWD/URL/etc. would all need altering for your details. |
Obviously, USER/PWD/URL/etc. would all need altering for your details. |
||
For gmail, make sure you enable https://myaccount.google.com/lesssecureapps |
For gmail, make sure you enable https://myaccount.google.com/lesssecureapps |
||
<!--< |
<!--<syntaxhighlight lang="phix">(notonline)--> |
||
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (libcurl)</span> |
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (libcurl)</span> |
||
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #000000;">libcurl</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #000000;">libcurl</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
||
Line 1,351: | Line 1,351: | ||
<span style="color: #7060A8;">curl_easy_cleanup</span><span style="color: #0000FF;">(</span><span style="color: #000000;">curl</span><span style="color: #0000FF;">)</span> |
<span style="color: #7060A8;">curl_easy_cleanup</span><span style="color: #0000FF;">(</span><span style="color: #000000;">curl</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #7060A8;">curl_global_cleanup</span><span style="color: #0000FF;">()</span> |
<span style="color: #7060A8;">curl_global_cleanup</span><span style="color: #0000FF;">()</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
< |
<syntaxhighlight lang="php">mail('hello@world.net', 'My Subject', "A Message!", "From: my@address.com");</syntaxhighlight> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
PicoLisp has a built-in '[http://software-lab.de/doc/refM.html#mail mail]' |
PicoLisp has a built-in '[http://software-lab.de/doc/refM.html#mail mail]' |
||
function. A minimal call would be |
function. A minimal call would be |
||
< |
<syntaxhighlight lang="picolisp">(mail "localhost" 25 "me@from.org" "you@to.org" "Subject" NIL "Hello")</syntaxhighlight> |
||
Instead of "Hello" an arbitrary number of arguments may follow (possibly |
Instead of "Hello" an arbitrary number of arguments may follow (possibly |
||
containing executable expressions) for the message body. |
containing executable expressions) for the message body. |
||
Line 1,368: | Line 1,368: | ||
Untested: |
Untested: |
||
< |
<syntaxhighlight lang="pike">int main(){ |
||
string to = "some@email.add"; |
string to = "some@email.add"; |
||
string subject = "Hello There."; |
string subject = "Hello There."; |
||
Line 1,375: | Line 1,375: | ||
Protocols.SMTP.Client()->simple_mail(to,subject,from,msg); |
Protocols.SMTP.Client()->simple_mail(to,subject,from,msg); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
Line 1,381: | Line 1,381: | ||
The parameters are splatted with a hashtable: |
The parameters are splatted with a hashtable: |
||
<syntaxhighlight lang="powershell"> |
|||
<lang PowerShell> |
|||
[hashtable]$mailMessage = @{ |
[hashtable]$mailMessage = @{ |
||
From = "weirdBoy@gmail.com" |
From = "weirdBoy@gmail.com" |
||
Line 1,396: | Line 1,396: | ||
Send-MailMessage @mailMessage |
Send-MailMessage @mailMessage |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
< |
<syntaxhighlight lang="purebasic">InitNetwork() |
||
CreateMail(0, "from@mydomain.com", "This is the Subject") |
CreateMail(0, "from@mydomain.com", "This is the Subject") |
||
Line 1,413: | Line 1,413: | ||
Else |
Else |
||
MessageRequester("Error", "Can't sent the mail !") |
MessageRequester("Error", "Can't sent the mail !") |
||
EndIf</ |
EndIf</syntaxhighlight> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Line 1,421: | Line 1,421: | ||
Tested on Windows, it should work on all [[wp:POSIX|POSIX]] platforms. |
Tested on Windows, it should work on all [[wp:POSIX|POSIX]] platforms. |
||
< |
<syntaxhighlight lang="python">import smtplib |
||
def sendemail(from_addr, to_addr_list, cc_addr_list, |
def sendemail(from_addr, to_addr_list, cc_addr_list, |
||
Line 1,438: | Line 1,438: | ||
problems = server.sendmail(from_addr, to_addr_list, message) |
problems = server.sendmail(from_addr, to_addr_list, message) |
||
server.quit() |
server.quit() |
||
return problems</ |
return problems</syntaxhighlight> |
||
Example use: |
Example use: |
||
< |
<syntaxhighlight lang="python">sendemail(from_addr = 'python@RC.net', |
||
to_addr_list = ['RC@gmail.com'], |
to_addr_list = ['RC@gmail.com'], |
||
cc_addr_list = ['RC@xx.co.uk'], |
cc_addr_list = ['RC@xx.co.uk'], |
||
Line 1,447: | Line 1,447: | ||
message = 'Howdy from a python function', |
message = 'Howdy from a python function', |
||
login = 'pythonuser', |
login = 'pythonuser', |
||
password = 'XXXXX')</ |
password = 'XXXXX')</syntaxhighlight> |
||
{{out|Sample Email received}} |
{{out|Sample Email received}} |
||
Line 1,463: | Line 1,463: | ||
Using Outlook COM server with the Pywin32 library. |
Using Outlook COM server with the Pywin32 library. |
||
< |
<syntaxhighlight lang="python">import win32com.client |
||
def sendmail(to, title, body): |
def sendmail(to, title, body): |
||
Line 1,475: | Line 1,475: | ||
ol.Quit() |
ol.Quit() |
||
sendmail("somebody@somewhere", "Title", "Hello")</ |
sendmail("somebody@somewhere", "Title", "Hello")</syntaxhighlight> |
||
=={{header|R}}== |
=={{header|R}}== |
||
Line 1,483: | Line 1,483: | ||
Using Outlook COM server with the '''[http://www.omegahat.net/RDCOMClient/ RDCOMClient]''' package. |
Using Outlook COM server with the '''[http://www.omegahat.net/RDCOMClient/ RDCOMClient]''' package. |
||
< |
<syntaxhighlight lang="r">library(RDCOMClient) |
||
send.mail <- function(to, title, body) { |
send.mail <- function(to, title, body) { |
||
Line 1,496: | Line 1,496: | ||
} |
} |
||
send.mail("somebody@somewhere", "Title", "Hello")</ |
send.mail("somebody@somewhere", "Title", "Hello")</syntaxhighlight> |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
Racket has a built-in library for sending e-mails: |
Racket has a built-in library for sending e-mails: |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang racket |
#lang racket |
||
Line 1,526: | Line 1,526: | ||
"Subject") |
"Subject") |
||
'("Hello World!")) |
'("Hello World!")) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
<lang |
<syntaxhighlight lang="raku" line>use Email::Simple; |
||
my $to = 'mail@example.com'; |
my $to = 'mail@example.com'; |
||
Line 1,580: | Line 1,580: | ||
} |
} |
||
} |
} |
||
)</ |
)</syntaxhighlight> |
||
=={{header|REBOL}}== |
=={{header|REBOL}}== |
||
< |
<syntaxhighlight lang="rebol">send user@host.dom "My message"</syntaxhighlight> |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Line 1,589: | Line 1,589: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
load "stdlib.ring" |
load "stdlib.ring" |
||
See "Send email..." + nl |
See "Send email..." + nl |
||
Line 1,606: | Line 1,606: | ||
CalmoSoft") |
CalmoSoft") |
||
see "Done.." + nl |
see "Done.." + nl |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 1,620: | Line 1,620: | ||
Uses the {{libheader|RubyGems}} gems [http://tmail.rubyforge.org TMail] which allows us to manipulate email objects conveniently, and [http://mime-types.rubyforge.org/ mime-types] which guesses a file's mime type based on its filename. |
Uses the {{libheader|RubyGems}} gems [http://tmail.rubyforge.org TMail] which allows us to manipulate email objects conveniently, and [http://mime-types.rubyforge.org/ mime-types] which guesses a file's mime type based on its filename. |
||
< |
<syntaxhighlight lang="ruby">require 'base64' |
||
require 'net/smtp' |
require 'net/smtp' |
||
require 'tmail' |
require 'tmail' |
||
Line 1,696: | Line 1,696: | ||
:password => 'secret' |
:password => 'secret' |
||
} |
} |
||
)</ |
)</syntaxhighlight> |
||
=={{header|SAS}}== |
=={{header|SAS}}== |
||
< |
<syntaxhighlight lang="sas">filename msg email |
||
to="afriend@someserver.com" |
to="afriend@someserver.com" |
||
cc="anotherfriend@somecompany.com" |
cc="anotherfriend@somecompany.com" |
||
Line 1,708: | Line 1,708: | ||
file msg; |
file msg; |
||
put "Hello, Connected World!"; |
put "Hello, Connected World!"; |
||
run;</ |
run;</syntaxhighlight> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
{{libheader|Scala}} |
{{libheader|Scala}} |
||
< |
<syntaxhighlight lang="scala">import java.util.Properties |
||
import javax.mail.internet.{ InternetAddress, MimeMessage } |
import javax.mail.internet.{ InternetAddress, MimeMessage } |
||
Line 1,745: | Line 1,745: | ||
Transport.send(message) |
Transport.send(message) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|SQL PL}}== |
=={{header|SQL PL}}== |
||
Line 1,751: | Line 1,751: | ||
With SQL PL: |
With SQL PL: |
||
You must first set the SMTP server in the database from which you want to send the message. |
You must first set the SMTP server in the database from which you want to send the message. |
||
< |
<syntaxhighlight lang="sql pl"> |
||
UPDATE DB CFG FOR myDb USING SMTP_SERVER 'smtp.ibm.com'; |
UPDATE DB CFG FOR myDb USING SMTP_SERVER 'smtp.ibm.com'; |
||
CALL UTL_MAIL.SEND ('senderAccount@myDomain.com','recipientAccount@yourDomain.com', 'copy@anotherDomain.com', NULL, 'The subject of the message', 'The content of the message'); |
CALL UTL_MAIL.SEND ('senderAccount@myDomain.com','recipientAccount@yourDomain.com', 'copy@anotherDomain.com', NULL, 'The subject of the message', 'The content of the message'); |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 1,770: | Line 1,770: | ||
{{tcllib|mime}}{{tcllib|smtp}} |
{{tcllib|mime}}{{tcllib|smtp}} |
||
Also may use the [http://tls.sourceforge.net/ tls] package (needed for sending via gmail). |
Also may use the [http://tls.sourceforge.net/ tls] package (needed for sending via gmail). |
||
< |
<syntaxhighlight lang="tcl">package require smtp |
||
package require mime |
package require mime |
||
package require tls |
package require tls |
||
Line 1,792: | Line 1,792: | ||
} |
} |
||
send_simple_message recipient@example.com "Testing" "This is a test message."</ |
send_simple_message recipient@example.com "Testing" "This is a test message."</syntaxhighlight> |
||
=={{header|TUSCRIPT}}== |
=={{header|TUSCRIPT}}== |
||
works only with Windows, on Linux OS it is possible to send an email by using the Execute function |
works only with Windows, on Linux OS it is possible to send an email by using the Execute function |
||
< |
<syntaxhighlight lang="tuscript"> |
||
$$ MODE TUSCRIPT |
$$ MODE TUSCRIPT |
||
Line 1,811: | Line 1,811: | ||
ENDIF |
ENDIF |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|TXR}}== |
=={{header|TXR}}== |
||
< |
<syntaxhighlight lang="txr">#!/usr/bin/txr |
||
@(next :args) |
@(next :args) |
||
@(cases) |
@(cases) |
||
Line 1,836: | Line 1,836: | ||
@(end) |
@(end) |
||
. |
. |
||
@(end)</ |
@(end)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,857: | Line 1,857: | ||
=={{header|VBA}}== |
=={{header|VBA}}== |
||
< |
<syntaxhighlight lang="vb">Option Explicit |
||
Const olMailItem = 0 |
Const olMailItem = 0 |
||
Line 1,875: | Line 1,875: | ||
Sub Test() |
Sub Test() |
||
SendMail "somebody@somewhere", "Title", "Hello" |
SendMail "somebody@somewhere", "Title", "Hello" |
||
End Sub</ |
End Sub</syntaxhighlight> |
||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
<syntaxhighlight lang="vb"> |
|||
<lang vb> |
|||
Function send_mail(from,recipient,cc,subject,message) |
Function send_mail(from,recipient,cc,subject,message) |
||
With CreateObject("CDO.Message") |
With CreateObject("CDO.Message") |
||
Line 1,899: | Line 1,899: | ||
Call send_mail("Alerts@alerts.org","jkspeed@jkspeed.org","","Test Email","this is a test message") |
Call send_mail("Alerts@alerts.org","jkspeed@jkspeed.org","","Test Email","this is a test message") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
Line 1,905: | Line 1,905: | ||
{{libheader|WrenGo}} |
{{libheader|WrenGo}} |
||
An embedded application with a Go host so we can use their net/smtp module. |
An embedded application with a Go host so we can use their net/smtp module. |
||
< |
<syntaxhighlight lang="ecmascript">/* send_email.wren */ |
||
foreign class Authority { |
foreign class Authority { |
||
Line 2,000: | Line 2,000: | ||
System.print("\nSending message...") |
System.print("\nSending message...") |
||
m.send(host, port, user, pass) |
m.send(host, port, user, pass) |
||
System.print("Message sent.")</ |
System.print("Message sent.")</syntaxhighlight> |
||
<br> |
<br> |
||
We now embed this script in the following Go program and run it. |
We now embed this script in the following Go program and run it. |
||
< |
<syntaxhighlight lang="go">/* go run send_email.go */ |
||
package main |
package main |
||
Line 2,078: | Line 2,078: | ||
vm.InterpretFile(fileName) |
vm.InterpretFile(fileName) |
||
vm.Free() |
vm.Free() |
||
}</ |
}</syntaxhighlight> |