Send email: Difference between revisions

3,044 bytes added ,  2 months ago
Added FreeBASIC
m (syntax highlighting fixup automation)
(Added FreeBASIC)
 
(2 intermediate revisions by 2 users not shown)
Line 506:
 
=={{header|Fantom}}==
 
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.
 
Line 565 ⟶ 564:
end program</syntaxhighlight>
 
=={{header|GoFreeBASIC}}==
===FB: LINUX===
Unfortunately, FreeBASIC does not have a built-in library for sending emails. However, you can use an external program such as <code>sendmail</code> or <code>mailx</code> that can be invoked from FreeBASIC using the <code>SHELL</code> function.
 
<syntaxhighlight lang="vbnet">Sub SendEmail(fromAddress As String, toAddress As String, ccAddress As String, _
subject As String, messageText As String, serverName As String, loginDetails As String)
Dim As String comando
comando = "echo '" & messageText & "' | mailx -s '" & subject & "' -r '" _
& fromAddress & "' -S smtp='" & serverName _
& "' -S smtp-auth=login -S smtp-auth-user='" & loginDetails _
& "' -S smtp-auth-password='yourpassword' -c '" & ccAddress & "' '" _
& toAddress & "'"
Shell comando
End Sub
 
Dim As String fromAddress = "your_mail@gmail.com"
Dim As String toAddress = "recipient@gmail.com"
Dim As String ccAddress = "cc@gmail.com"
Dim As String subject = "Mail subject"
Dim As String messageText = "This is the body of the email."
Dim As String serverName = "smtp.gmail.com"
Dim As String loginDetails = "your_username"
</syntaxhighlight>
 
And then call this script from FreeBASIC using the <code>SHELL</code> function:
<syntaxhighlight lang="vbnet">
SendEmail(fromAddress, toAddress, ccAddress, subject, messageText, serverName, loginDetails)
</syntaxhighlight>
 
===FB: WINDOWS===
FreeBASIC does not have a built-in library for interacting with Outlook.
An alternative is to write a script in VBA or VBScript to send email through Outlook, and then call that script from FreeBASIC.
 
<syntaxhighlight lang="vbnet">'VBScript code:
Function EnviarCorreo()
With CreateObject("CDO.Message")
.Subject = "Mail subject"
.From = "your_mail@domain.com"
.To = "recipient@domain.com"
.TextBody = "This is the body of the email."
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smtp.dominio.com"
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Configuration.Fields.Update
.Send
End With
End Function</syntaxhighlight>
 
<syntaxhighlight lang="vbnet">'VBA code:
Sub EnviarCorreo()
Dim OutlookApp As Object
Dim OutlookMail As Object
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
With OutlookMail
.To = "recipient@domain.com"
.Subject = "Mail subject"
.Body = "This is the body of the email."
.Send
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub</syntaxhighlight>
 
And then call this script from FreeBASIC using the <code>SHELL</code> function:
<syntaxhighlight lang="vbnet">
Shell "cscript send_mail.vbs"
</syntaxhighlight>
 
=={{header|Go}}==
A full little command-line program that can be used to send simple e-mails. Uses the built-in smtp package.
Supports TLS connections.
Line 1,202 ⟶ 1,277:
 
=={{header|Perl}}==
===Using Net::SMTP===
This subroutine throws an appropriate error if it fails to connect to the server or authenticate. It should work on any platform Perl does.
 
Line 1,211 ⟶ 1,287:
# Authen::SASL here.
 
sub send_email {
{ my %o =
(from => '', to => [], cc => [],
subject => '', body => '',
Line 1,219 ⟶ 1,295:
ref $o{$_} or $o{$_} = [$o{$_}] foreach 'to', 'cc';
 
my $smtp = new Net::SMTP->new($o{host} ? $o{host} : ())
or die "Couldn't connect to SMTP server";
 
Line 1,236 ⟶ 1,312:
$smtp->dataend;
 
return 1;}</syntaxhighlight>
}</syntaxhighlight>
 
An example call:
Line 1,256 ⟶ 1,333:
user => 'tappman@example.com';</syntaxhighlight>
 
===Using LWP===
{{libheader|LWP}}
 
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-&gt;post()</code> method does not suit since it constructs a message as MIME "form data".
 
Line 1,905 ⟶ 1,981:
{{libheader|WrenGo}}
An embedded application with a Go host so we can use their net/smtp module.
<syntaxhighlight lang="ecmascriptwren">/* send_emailSend_email.wren */
 
foreign class Authority {
Line 2,003 ⟶ 2,079:
<br>
We now embed this script in the following Go program and run it.
<syntaxhighlight lang="go">/* go run send_emailSend_email.go */
 
package main
Line 2,063 ⟶ 2,139:
func main() {
vm := wren.NewVM()
fileName := "send_emailSend_email.wren"
 
smtpMethodMap := wren.MethodMap { "static sendMail(_,_,_,_,_)": sendMail }
2,136

edits