Today I was working on the mvc app I am building for a customer. We need to send email from the app so I used the system.net.mail feature in .Net. As part of this, I need a Windows 7 smtp server. So I found the smtp4dev app on codeplex. I found it on this nice blog http://social.technet.microsoft.com/Forums/en-US/w7itproinstall/thread/f73a7f0f-a17c-4a48-a42c-8da8e36f6cc6. Check out the notes titled “Mikeyyyy, this is how I made it work on Windows 7 64-bit with IIS 7.5 I hope it helps.” a good ways down.
And in case you need it, heres a couple of methods I setup to send email. The 2nd method takes a string of emails separated by ; and splits them into a generic list which then is used to load up the addresses.
Public Sub SendEmail(ToEmailAddress As String, FromEmailAddress As String, Subject As String, TextToMail As String)
Dim message As New MailMessage()
Dim client As New SmtpClient(m_SMTPServer)
Dim emailList As New List(Of String)
Dim bcc As String = someMail@here.com;anothermail@here.com
Try
emailList = GetEmailsAsList(ToEmailAddress)
For Each email As String In emailList
message.To.Add(New MailAddress(email))
Next
message.From = New MailAddress(FromEmailAddress)
emailList = GetEmailsAsList(bcc)
For Each email As String In emailList
message.Bcc.Add(email)
Next
message.IsBodyHtml = True
message.Subject = Subject
message.Body = TextToMail
client.Send(message)
Catch ex As Exception
Throw ex
End Try
End Sub
Private Function GetEmailsAsList(EmailAddresses As String) As List(Of String)
Dim i As Integer
Dim emailList As New List(Of String)
i = EmailAddresses.IndexOf(";")
If i > -1 Then
Dim emailArray() As String
emailArray = EmailAddresses.Split(";")
For Each email As String In emailArray
emailList.Add(email)
Next
Else
emailList.Add(EmailAddresses)
End If
Return emailList
End Function