Send email: Difference between revisions

Added FreeBASIC
m (→‎{{header|Perl}}: future-proof for 5.36)
(Added FreeBASIC)
 
(One intermediate revision by one other user 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,906 ⟶ 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,004 ⟶ 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,064 ⟶ 2,139:
func main() {
vm := wren.NewVM()
fileName := "send_emailSend_email.wren"
 
smtpMethodMap := wren.MethodMap { "static sendMail(_,_,_,_,_)": sendMail }
2,123

edits