# MailKit
Simple example:
```fsharp
#r "nuget: MailKit"
#r "nuget: MimeKit"
open MimeKit
open MailKit.Net.Smtp
let smtpServerAddress = ""
let smtpServerPort = ""
let userName = ""
let password = ""
let message = new MimeMessage(Subject = "")
message.From.Add (MailboxAddress("Scripts", "
[email protected]"))
message.To.Add(MailboxAddress("Nikola Milekic", "
[email protected]"))
message.Body <- new TextPart("plain", Text = "")
let smtpClient = new SmtpClient()
smtpClient.Connect(smtpServerAddress, int smtpServerPort)
printfn "Connected to SMTP"
smtpClient.Authenticate(userName, password)
printfn "Authenticated"
smtpClient.Send message |> ignore
printfn "Message Sent"
smtpClient.Disconnect true
printfn "Done"
```
To attach an attachment, instead of setting `Body` to `TextPart` you need to use the `BodyBuilder`:
```fsharp
let bodyBuilder = BodyBuilder()
bodyBuilder.Attachments.Add attachmentFilePath |> ignore
message.Body <- bodyBuilder.ToMessageBody()
```
## Combined with Connect Client
```fsharp
#r "nuget: Fs1PasswordConnect"
open Fs1PasswordConnect
let client = ConnectClient.fromEnvironmentVariables () |> Result.get
let item : Item =
client.GetItem (VaultTitle "Automation", ItemId "ltioiqoelvcvprblrfgim3lsui")
|> Async.RunSynchronously
|> Result.get
let { Value = FieldValue userName } = item.Fields |> List.find(fun x -> x.Label = FieldLabel "username")
let { Value = FieldValue password } = item.Fields |> List.find(fun x -> x.Label = FieldLabel "password")
let { Value = FieldValue smtpServerAddress } = item.Fields |> List.find(fun x -> x.Label = FieldLabel "Address")
let { Value = FieldValue smtpServerPort } = item.Fields |> List.find(fun x -> x.Label = FieldLabel "Port")
```