As a follow up to my post SPF compliant CDO message, here is the equivalent (well, not quite, but similar) vb.net version that I use –
Public Sub Send(ByVal strTo As String, ByVal strFrom As String, _
ByVal strSender As String, ByVal strCC As String, _
ByVal strBCC As String, ByVal strSubject As String, _
ByVal strBody As String)
Dim MailObj As New System.Net.Mail.MailMessage(strFrom, _
strTo, strSubject, strBody)
'SPF Stuff
If Not String.IsNullOrEmpty(strSender) And strSender <> strFrom Then
MailObj.Headers.Add("return-path", strSender)
MailObj.Headers.Add("reply-to", strFrom)
MailObj.Sender = New Net.Mail.MailAddress(strSender)
End If
If Not strCC = String.Empty Then
For Each cc As String In strCC.Split(";")
MailObj.CC.Add(cc)
Next
End If
If Not strBCC = String.Empty Then
For Each bcc As String In strBCC.Split(";")
MailObj.Bcc.Add(bcc)
Next
End If
Dim MailClient As New System.Net.Mail.SmtpClient
MailClient.Host = "mailserver"
MailClient.Send(MailObj)
End Sub
Again, as before, this is generally useful for web generated emails (like send a friend forms etc.), simply specify the users address as strFrom and a generic local address (noreply@mydomain.com) as strSender.
I hope it proves useful.


















Leave a comment