SPF compliant .net system.net.mail .mailmessage

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.

add to del.icio.us :: Bookmark Post in Technorati :: Add to Blinkslist :: add to furl :: Digg it :: add to ma.gnolia :: Stumble It! :: add to simpy :: seed the vine :: :: :: TailRank :: post to facebook :: Bookmark on Google :: Add to Netscape :: Share on Yahoo :: Add this to Live

Visual Studio 2005 + Vista = Annoying

I’ve recently upgraded to vista on my laptop at work and am getting increasingly annoyed by one ‘broken’ aspect. Why can I no longer drag files from an explorer window into a ‘Solution Explorer’ in VS?

I’m assuming it’s something to do with them running as slightly different users as I have to run VS ‘as administrator’, well that’s what MS advises anyway.

I do hope this is fixed soon!

GetAbsoluteURL (.net)

I needed a way to easily convert a relative URL to an absolute URL for a link within a project I’m currently working on. I imagined I’d have to roll something myself and was starting to think it would have to be pretty complex… then .net suprised me 😉

Public Function GetAbsoluteUrl(ByVal currUrl As String, _
ByVal relUrl As String) As String
Dim baseUrl As New Uri(currUrl)
Dim destUrl As New Uri(baseUrl, relUrl)
Return destUrl.AbsoluteUri
End Function

Now that is nifty 🙂

Conditional JavaScript in ASP.Net

Now this is annoying me, I’m trying to take an existing classic ASP solution and convert it to ASP.Net 2.0 as a learning exercise. The problem is that I’m struggling to convert this –

<head>
<title>A Page</title>
<% if intCategoryID < 3 then %>
<script language="javaScript"
src="http://www.foo.com/foo.js"></script>
<% end if %>
</head>

So, I want to only include the JavaScript if a condition is met (in this case intCategoryID < 3). How do I achieve this in ASP.Net?? I have looked at an asp:literal tag to achieve this but Visual Web Developer suggests a literal cannot include child tags (the script tag itself). Can I add one programmatically from the codebehind?

I hope I can find a solution to this..

Posted in .Net. 3 Comments »

.NET Framework Version 2.0 Released

The final version of the .Net framework 2.0 has been released, grab it here –
Download details: .NET Framework Version 2.0 Redistributable Package (x86)