How to generate emails from Microsoft Outlook when writing code in C# on a Windowns platform using VS2005?

I am developing a C# Windows platform application using VS2005.

Do you know how the following VBA Access code could be rewritten into C# code?

I am trying to generate emails from Microsoft Outlook.

Sub sndEmailTest1Fall()
    On Error GoTo SndEmailTest1_ErrorHandler                  
    Dim iMsg As Object
    Dim iConf As Object
    Dim rsList As ADODB.Recordset
    Dim rsBranch As ADODB.Recordset
    Dim cn As ADODB.Connection
    Dim cn2 As ADODB.Connection
    Dim Flds As Object
    Dim str_sql1 As String
    Dim str_sql2 As String
    Dim str_BCC As String
    Dim str_From As String
    Dim str_To As String
    Dim intRec As Integer
    Dim rs As ADODB.Recordset
    Dim strPreviousBranch
    Dim strConcat_EmailAdd
    Dim strConcat_EmailAdd_New
    Dim sMail As String, rsCur, rsPrev
    Dim LResult As String
    Dim strBranch As String
    Dim sMailConst As String
    Set rsList = New ADODB.Recordset
    Set rsBranch = New ADODB.Recordset
    Set cn = CurrentProject.Connection
    Set cn2 = CurrentProject.Connection
    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")
    Set Flds = iConf.Fields
    With Flds
        .Item("") = 5555
        .Item("") = ""
        .Item("") = 7777
    End With
    str_sql1 = "If  Exists(SELECT * FROM dbo.SYSOBJECTS WHERE NAME = 'tblProblemBranch' AND TYPE = 'U') DELETE FROM tblProblemBranch"
    DoCmd.RunSQL (str_sql1)
     With rsList
    .Open "SELECT DISTINCT E.Branch, E.EMAILADD From tblPSEmail", cn, 2, 2
     Do Until .EOF
        strBranch = .Fields("Branch")
        Do Until strBranch <> .Fields("Branch")
            sMail = sMail & .Fields("EMailAdd") & ";"
            If .EOF Then
                Exit Do
            End If
       LResult = Mid(sMail, 1, 1)
       If LResult <> "#" Then
          Set iMsg = CreateObject("CDO.Message")
          With iMsg
             Set .Configuration = iConf
             .To = str_To
             .Subject = "UDL Branch " & strBranch
              ExportedFile = "\\ny" & strBranch & ".XLS"
              If isFileExist(ExportedFile) Then Sort_add_Pagebreak ExportedFile
              .AddAttachment "\\ny" & strBranch & ".XLS"            
              Me!lblBranch.Caption = "Email Branch " & strBranch
          End With      
       End If
       Set iMsg = Nothing
Who is Participating?
borkiConnect With a Mentor Commented:
You could try the VB to C# converter, even though VBA is not VB.NET, they are similar languages in many ways.

With regards to interfacing with Outlook, I use vbMAPI for anything I do with Outlook, it really makes Outlook programming a breeze. The developer claims it works well with C#.

Good luck!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.