Here's a piece of code that I use all the time. I've added code now for multiple CCs and an attachment
Public Sub sendMail(ByVal strBody As String, ByVal strSubject As String, ByVal strFilename As String)
Try
Dim strServer As String = System.Configuration.ConfigurationManager.AppSettings("emailserver")
Dim strUser As String = System.Configuration.ConfigurationManager.AppSettings("emailuser")
Dim strPassword As String = System.Configuration.ConfigurationManager.AppSettings("emailpassword")
Dim strTo As String = System.Configuration.ConfigurationManager.AppSettings("emailTo")
Dim strCC As String = System.Configuration.ConfigurationManager.AppSettings("emailCC")
Dim strCCArray() As String = strCC.Split(";")
Dim mail As New System.Net.Mail.MailMessage(strUser, strTo)
For Each cc In strCCArray
mail.CC.Add(cc)
Next
mail.Subject = strSubject
mail.Body = strBody
mail.IsBodyHtml = True
mail.Priority = Net.Mail.MailPriority.Normal
Dim att As New Net.Mail.Attachment(strFilename, "image/x-portable-bitmap")
mail.Attachments.Add(att)
Dim serv As New System.Net.Mail.SmtpClient(strServer)
If strUser > "" And strPassword > "" Then
serv.Credentials = New System.Net.NetworkCredential(strUser, strPassword)
End If
'serv.UseDefaultCredentials = False
'serv.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
serv.Send(mail)
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
End Sub
Here's the app.config code:
<appSettings>
<add key="emailserver" value="mymailserver"/>
<add key="emailuser" value=""/>
<add key="emailpassword" value=""/>
<add key="emailTo" value=""/>
<add key="emailCC" value=<a href="mailto:me@nowhere.com;me@somewhere.com">me@nowhere.com;me@somewhere.com</a>/>
</appSettings>