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(";")
End If

If Not strBCC = String.Empty Then
   For Each bcc As String In strBCC.Split(";")
End If

Dim MailClient As New System.Net.Mail.SmtpClient
MailClient.Host = "mailserver"

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 –

<title>A Page</title>
<% if intCategoryID < 3 then %>
<script language="javaScript"
<% end if %>

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)

Using firefox with Visual Web Developer

One of the things that’s been really annoying me as that I’ve been forced to use IE to test pages with the ASP.NET Development Server. This is due to NTLM for authentication to the site. However by following the instructions in the link below, firefox now works 🙂 (the comma separated list of servers just needs to be localhost, although I did add my machine name too)
Firefox and Sharepoint

Learning ASP.Net 2.0

I’m currently trying to learn ASP.Net 2.0 using the new Visual Web Developer Express IDE. This is kind of different for me as I’ve been a classic ASP developer for many a year now and have always use a text editor for all my development. I’m guessing the best way to approach this is to take an existing ASP solution which I have previously written and try to rewrite it in .Net which is of course a completely different way of thinking. If anyone has any suggestions of good books/sites or anything I should be using then let me know.