I am using the following in a scheduled task that does not require portalsettings:
DotNetNuke.Services.Mail.Mail.SendMail(strFromEmail, strToEmail, "", strSubject, strContent, "", "HTML", "", "", "", "")
If for whatever reason you cannot use the above, the following should work to get portalsettings:
Dim portalSettings As PortalSettings = PortalController.GetCurrentPortalSettings()
Worst case, here is a function to build your own portalsettings:
Public Shared Function CreateNewPortalSettings(ByVal portalId As Integer) As DotNetNuke.Entities.Portals.PortalSettings
'new settings object
Dim ps As New PortalSettings()
'controller instances
Dim pc As New PortalController()
Dim tc As New TabController()
Dim pac As New PortalAliasController()
'get the first portal alias found to be used as the current portal alias
Dim portalAlias As PortalAliasInfo = Nothing
Dim aliases As Entities.Portals.PortalAliasCollection = pac.GetPortalAliasByPortalID(portalId)
Dim aliasKey As String = ""
If aliases IsNot Nothing AndAlso aliases.Count > 0 Then
'get the first portal alias in the list and use that
For Each key As String In aliases.Keys
aliasKey = key
portalAlias = aliases(key)
Exit For
Next
End If
'get the portal and copy across the settings
Dim portal As PortalInfo = pc.GetPortal(portalId)
If portal IsNot Nothing Then
ps.PortalAlias = portalAlias
ps.PortalId = portal.PortalID
ps.PortalName = portal.PortalName
ps.LogoFile = portal.LogoFile
ps.FooterText = portal.FooterText
ps.ExpiryDate = portal.ExpiryDate
ps.UserRegistration = portal.UserRegistration
ps.BannerAdvertising = portal.BannerAdvertising
ps.Currency = portal.Currency
ps.AdministratorId = portal.AdministratorId
ps.Email = portal.Email
ps.HostFee = portal.HostFee
ps.HostSpace = portal.HostSpace
ps.PageQuota = portal.PageQuota
ps.UserQuota = portal.UserQuota
ps.AdministratorRoleId = portal.AdministratorRoleId
ps.AdministratorRoleName = portal.AdministratorRoleName
ps.RegisteredRoleId = portal.RegisteredRoleId
ps.RegisteredRoleName = portal.RegisteredRoleName
ps.Description = portal.Description
ps.KeyWords = portal.KeyWords
ps.BackgroundFile = portal.BackgroundFile
ps.GUID = portal.GUID
ps.SiteLogHistory = portal.SiteLogHistory
ps.AdminTabId = portal.AdminTabId
ps.SuperTabId = portal.SuperTabId
ps.SplashTabId = portal.SplashTabId
ps.HomeTabId = portal.HomeTabId
ps.LoginTabId = portal.LoginTabId
ps.UserTabId = portal.UserTabId
ps.DefaultLanguage = portal.DefaultLanguage
ps.TimeZoneOffset = portal.TimeZoneOffset
ps.HomeDirectory = portal.HomeDirectory
ps.Version = portal.Version
'ps.AdminSkin = DotNetNuke.UI.Skins.SkinController.ge(SkinInfo.RootSkin, portalId, SkinType.Admin)
'If ps.AdminSkin Is Nothing Then
' ps.AdminSkin = SkinController.GetSkin(SkinInfo.RootSkin, DotNetNuke.Common.Utilities.Null.NullInteger, SkinType.Admin)
'End If
'ps.PortalSkin = SkinController.GetSkin(SkinInfo.RootSkin, portalId, SkinType.Portal)
'If ps.PortalSkin Is Nothing Then
' ps.PortalSkin = SkinController.GetSkin(SkinInfo.RootSkin, DotNetNuke.Common.Utilities.Null.NullInteger, SkinType.Portal)
'End If
'ps.AdminContainer = SkinController.GetSkin(SkinInfo.RootContainer, portalId, SkinType.Admin)
'If ps.AdminContainer Is Nothing Then
' ps.AdminContainer = SkinController.GetSkin(SkinInfo.RootContainer, DotNetNuke.Common.Utilities.Null.NullInteger, SkinType.Admin)
'End If
'ps.PortalContainer = SkinController.GetSkin(SkinInfo.RootContainer, portalId, SkinType.Portal)
'If ps.PortalContainer Is Nothing Then
' ps.PortalContainer = SkinController.GetSkin(SkinInfo.RootContainer, DotNetNuke.Common.Utilities.Null.NullInteger, SkinType.Portal)
'End If
ps.Pages = portal.Pages
ps.Users = portal.Users
' set custom properties
If DotNetNuke.Common.Utilities.Null.IsNull(ps.HostSpace) Then
ps.HostSpace = 0
End If
If DotNetNuke.Common.Utilities.Null.IsNull(ps.DefaultLanguage) Then
ps.DefaultLanguage = DotNetNuke.Services.Localization.Localization.SystemLocale
End If
If DotNetNuke.Common.Utilities.Null.IsNull(ps.TimeZoneOffset) Then
ps.TimeZoneOffset = DotNetNuke.Services.Localization.Localization.SystemTimeZoneOffset
End If
ps.HomeDirectory = (DotNetNuke.Common.Globals.ApplicationPath & "/") + portal.HomeDirectory & "/"
' get application version
Dim arrVersion As String() = DotNetNuke.Common.Assembly.glbAppVersion.Split("."c)
Dim intMajor As Integer = 0
Dim intMinor As Integer = 0
Dim intBuild As Integer = 0
Int32.TryParse(arrVersion(0), intMajor)
Int32.TryParse(arrVersion(1), intMinor)
Int32.TryParse(arrVersion(2), intBuild)
ps.Version = ((intMajor.ToString() & ".") + intMinor.ToString() & ".") + intBuild.ToString()
End If
'Add each portal Tab to DekstopTabs
Dim portalTab As TabInfo = Nothing
Dim first As Boolean = True
For Each tabPair As KeyValuePair(Of Integer, TabInfo) In tc.GetTabsByPortal(ps.PortalId)
' clone the tab object ( to avoid creating an object reference to the data cache )
portalTab = tabPair.Value.Clone()
' set custom properties
If portalTab.TabOrder = 0 Then
portalTab.TabOrder = 999
End If
If DotNetNuke.Common.Utilities.Null.IsNull(portalTab.StartDate) Then
portalTab.StartDate = System.DateTime.MinValue
End If
If DotNetNuke.Common.Utilities.Null.IsNull(portalTab.EndDate) Then
portalTab.EndDate = System.DateTime.MaxValue
End If
ps.DesktopTabs.Add(portalTab)
'assign the first 'normal' tab as the active tab - could be the home tab, if it
'still exists, or it will be after the admin tab(s)
If first AndAlso (portalTab.TabID = portal.HomeTabId OrElse portalTab.TabID > portal.AdminTabId) Then
ps.ActiveTab = portalTab
first = False
End If
Next
'last gasp chance in case active tab was not set
If ps.ActiveTab Is Nothing Then
ps.ActiveTab = portalTab
End If
'Add each host Tab to DesktopTabs
Dim hostTab As TabInfo = Nothing
For Each tabPair As KeyValuePair(Of Integer, TabInfo) In tc.GetTabsByPortal(DotNetNuke.Common.Utilities.Null.NullInteger)
' clone the tab object ( to avoid creating an object reference to the data cache )
hostTab = tabPair.Value.Clone()
hostTab.PortalID = ps.PortalId
hostTab.StartDate = System.DateTime.MinValue
hostTab.EndDate = System.DateTime.MaxValue
ps.DesktopTabs.Add(hostTab)
Next
'now add the portal settings to the httpContext
If System.Web.HttpContext.Current Is Nothing Then
'if there is no HttpContext, then mock one up by creating a fake WorkerRequest
Dim appVirtualDir As String = DotNetNuke.Common.Globals.ApplicationPath
Dim appPhysicalDir As String = AppDomain.CurrentDomain.BaseDirectory
Dim page As String = ps.PortalAlias.HTTPAlias
Dim query As String = String.Empty
Dim output As System.IO.TextWriter = Nothing
'create a dummy simple worker request
Dim workerRequest As New System.Web.Hosting.SimpleWorkerRequest(page, query, output)
System.Web.HttpContext.Current = New System.Web.HttpContext(workerRequest)
End If
'stash the portalSettings in the Context Items, where the rest of the DNN Code expects it to be
System.Web.HttpContext.Current.Items.Add("PortalSettings", ps)
Return ps
End Function