This guide uses Visual Basic .NET and `System.Net.Mail`, not Excel VBA. It shows how to configure authenticated SMTP, send a message, and capture the delivered email in MailSlurp for verification.

If you need to send from Office VBA, use an Office-compatible mail library or call a server-side API without placing your MailSlurp API key in the workbook.

## Get SMTP server credentials

To send email from Visual Basic .NET, you need access to an SMTP server. This example uses MailSlurp SMTP credentials to configure the client. If you already have SMTP credentials, skip to the next step.



```vba
Dim webClient As New Net.WebClient
Dim jsonClient As New Net.WebClient
Dim apiKey As String = Environment.GetEnvironmentVariable("API_KEY")
Assert.IsNotEmpty(apiKey)
Assert.IsNotNull(apiKey)
webClient.Headers.Add("x-api-key", apiKey)
Dim imapSmtpAccessJson = webClient.DownloadString("https://api.mailslurp.com/inboxes/imap-smtp-access")
jsonClient.Headers.Add("Content-Type", "application/json")
Dim username = jsonClient.UploadString("https://api.mailslurp.com/user/json/pluck?property=smtpUsername", imapSmtpAccessJson)
jsonClient.Headers.Add("Content-Type", "application/json")
Dim password = jsonClient.UploadString("https://api.mailslurp.com/user/json/pluck?property=smtpPassword", imapSmtpAccessJson)
jsonClient.Headers.Add("Content-Type", "application/json")
Dim port = jsonClient.UploadString("https://api.mailslurp.com/user/json/pluck?property=smtpServerPort", imapSmtpAccessJson)
jsonClient.Headers.Add("Content-Type", "application/json")
Dim host = jsonClient.UploadString("https://api.mailslurp.com/user/json/pluck?property=smtpServerHost", imapSmtpAccessJson)
```



## Create an SMTP client

Next, take the password, username, host, and port and configure the SMTP client:



```vba
Dim Smtp_Server As New Net.Mail.SmtpClient
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential(username, password)
Smtp_Server.EnableSsl = False
Smtp_Server.Port = Integer.Parse(port)
Smtp_Server.Host = host
```



## Now send an email

Once configured, use the `Net.Mail.SmtpClient` instance to send an email:



```vba
Dim email As New Net.Mail.MailMessage()
email = New Net.Mail.MailMessage()
email.From = New Net.Mail.MailAddress(fromAddress)
email.To.Add(toAddress)
email.Subject = "Send email with VB"
email.IsBodyHtml = False
email.Body = "Hello this is me"
Smtp_Server.Send(email)
```





{{LANDING_SHORTCODE:POST_CTA_BANNER:%7B%22title%22%3A%22Preview%20emails%20sent%20from%20Visual%20Basic%20.NET%22%2C%22content%22%3A%22After%20the%20Visual%20Basic%20.NET%20SMTP%20send%20succeeds%2C%20capture%20the%20delivered%20message%20in%20MailSlurp%20and%20review%20it%20with%20%5BFree%20Email%20Render%5D(%2Ftools%2Ffree-email-render%2F)%20or%20device%20previews.%20That%20helps%20confirm%20links%2C%20fallback%20copy%2C%20and%20mobile%20readability%20before%20the%20workflow%20is%20reused.%22%2C%22buttonHref%22%3A%22%2Fproduct%2Fdevice-previews%2F%22%2C%22buttonText%22%3A%22Explore%20device%20previews%22%2C%22buttonTheme%22%3A%22blue%22%2C%22image%22%3A%22%2Fassets%2Fhome%2Fdevice-render-devices.png%22%2C%22imageAlt%22%3A%22Device%20previews%20for%20Visual%20Basic%20SMTP%20test%20emails%22%2C%22imageWidth%22%3A%22800%22%2C%22imageHeight%22%3A%22415%22%2C%22imagePosition%22%3A%22%22%7D}}



## Next steps

You can also use MailSlurp directly in Excel using Power Query. Check out the [guide here](/guides/read-email-in-excel-powerquery/).
