Quantcast
Channel: .NET Framework inside SQL Server forum
Viewing all articles
Browse latest Browse all 780

SQL and Email Problems

$
0
0
I am trying to get sql to download email for me. and put the body into sql. Here is where i got the code from. http://www.limilabs.com/blog/download-emails-with-sqlserver#comment-472876
Basically this is what happens. I create the dll then run the query to create assembly the assembly that creates the stored procedure. the stored procedure is not created. See bellow. I think my dll code is screwed up.

Here is what is happening
I am getting this error 

Msg 6505, Level 16, State 2, Procedure GetEmails, Line 2
Could not find Type 'StoredProcedures' in assembly 'SqlEmailDownloader'.

When I run this query in management studio.

Code:
USE HelloWorld
GO
EXEC sp_configure 'clr enabled' , '1'

GO

RECONFIGURE

GO
Alter Database HelloWorld Set TrustWorthy On

GO
CREATE ASSEMBLY [System.Windows.Forms] FROM 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll'
With Permission_Set=Unsafe

GO

CREATE ASSEMBLY SqlEmailDownloaderAssembly FROM 'E:\mail\SqlEmailDownloader.dll'

With Permission_Set=Unsafe

GO

CREATE PROCEDURE GetEmails

AS EXTERNAL NAME SqlEmailDownloaderAssembly.StoredProcedures.GetEmails

GO
My DLL looks like this
Code:
Imports System.Data
Imports Microsoft.SqlServer.Server
Imports Limilabs.Client.IMAP
Imports Limilabs.Mail
Public Class Class1
    Public Class StoredProcedures<Microsoft.SqlServer.Server.SqlProcedure()> _
        Public Shared Sub GetEmails()
            Dim record As New SqlDataRecord({ _
                New SqlMetaData("UID", SqlDbType.BigInt), _
                New SqlMetaData("Subject", SqlDbType.NVarChar, 128)})

            Using client As New Imap()
                client.Connect("Imap.gmail.com")
                client.Login("username", "password")
                client.SelectInbox()

                SqlContext.Pipe.SendResultsStart(record)
                For Each uid As Long In client.Search(Flag.Unseen)
                    Dim eml As String = client.PeekHeadersByUID(uid)
                    Dim email As IMail = New MailBuilder() _
                    .CreateFromEml(eml)

                    record.SetSqlInt64(0, uid)
                    record.SetSqlString(1, email.Subject)
                    SqlContext.Pipe.SendResultsRow(record)
                Next
                client.Close()
                SqlContext.Pipe.SendResultsEnd()
            End Using
        End Sub
    End Class



Viewing all articles
Browse latest Browse all 780

Trending Articles