2 ways to send email within SharePoint, using code

 

Using SPUtility.SendEmail (SharePoint way)

Try
Dim thisWeb As SPWeb = SPControl.GetContextWeb(Context)
Dim toField As String = “someone@microsoft.com
Dim subject As String = “Test Message”
Dim body As String = “Message sent from SharePoint”
Dim success As Boolean = SPUtility.SendEmail(thisWeb, True, True, toField, subject, body)
Catch ex As Exception
‘ handle exception
End Try

More info here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.sendemail.aspx

 

Using MailMessage (ASP.NET way)

Dim mm As New MailMessage(emailt.Text, ToAddress)

 

mm.Subject =”Test Message ”
dim body as New String
sbu.AppendLine(“nieuwe aanvraag tot registratie”)
mm.Body = body

mm.IsBodyHtml = False

Dim smtp As New SmtpClient

smtp.Send(mm)

 

More info here: http://msdn.microsoft.com/en-us/library/system.web.mail.mailmessage(VS.71).aspx

About: Marijn

Marijn Somers (MVP) has over 14 years experience in the SharePoint world, starting out with SP2007. Over the years the focus has grown to Office 365, with a focus on collaboration and document management. He is a business consultant at Balestra and Principal Content Provider for "Mijn 365 Coach" that offers dutch employee video training. His main work tracks are around user adoption, training and coaching and governance. He is also not afraid to dig deeper in the technicalities with PowerShell, adaptive cards or custom formatting in lists and libraries. You can listen to him on the biweekly "Office 365 Distilled" podcast.

%d bloggers like this: