Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

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("http://schemas.microsoft.com/cdo/configuration/sendusing") = 5555
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mta-hub.y.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 7777
        .Update
    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") & ";"
            .MoveNext
            If .EOF Then
                Exit Do
            End If
        Loop      
       
       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
              Me.Repaint
             .Send            
          End With      
       End If
       Set iMsg = Nothing
    Loop
ASKER CERTIFIED SOLUTION
Avatar of borki
borki
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Obadiah Christopher
Obadiah Christopher
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial