I have an app that I want to send an email to a user on our network. I do not have access to the SNMP info but I have an app working in VB and the code is below. I keep trying to get it to work in C# but no success. I am close I think with the chunk of code below the VB. Can someone help?
Code:'get recordset for email's body Dim OlApp As New Outlook.Application Dim OlNameSpace As Outlook.NameSpace Dim msg As Outlook.MailItem Dim strPath, strSubj As String Dim cn As New SqlConnection cn.ConnectionString = "workstation id=""S-KG-CFSCE-2098"";packet size=4096;integrated security=SSPI;data s" & _ "ource=""server"";persist security info=False;initial catalog=database" cn.Open() cmdtext = "Select * from VehicleReq2 where ReqNum = " & "'" & txtReqNum.Text & "'" da.SelectCommand = New SqlCommand(cmdtext, cn) Dim dr As SqlDataReader = da.SelectCommand.ExecuteReader 'get attachment - Current is a structure in the module Try msg = OlApp.CreateItem(Outlook.OlItemType.olMailItem) msg.To = "[email protected]" msg.Subject = "Vehicle Request " & num msg.Body = "Press Send to send now or add any comments to bottom. Do not change request data" & vbCrLf & vbCrLf While dr.Read msg.Body = "There is a new Vehicle Request. " & vbCrLf msg.Body = msg.Body & "Request Number: " & dr.GetValue(0) & vbCrLf msg.Body = msg.Body & "Date Ordered: " & dr.GetValue(1) & vbCrLf msg.Body = msg.Body & "Crse Number: " & dr.GetValue(2) & vbCrLf msg.Body = msg.Body & "DT Required: " & dr.GetValue(3) & vbCrLf msg.Body = msg.Body & "DT Released: " & dr.GetValue(4) & vbCrLf msg.Body = msg.Body & "Ordered by: " & dr.GetValue(5) & vbCrLf msg.Body = msg.Body & "Sqn: " & dr.GetValue(6) & vbCrLf msg.Body = msg.Body & "Local: " & dr.GetValue(7) & vbCrLf msg.Body = msg.Body & "Type of Ex: " & dr.GetValue(8) & vbCrLf msg.Body = msg.Body & "Ex Location: " & dr.GetValue(9) & vbCrLf End While msg.Display() Catch ex As Exception MessageBox.Show(ex.Message) End Try End IfCode:using Outlook = Microsoft.Office.Interop.Outlook; Outlook.Application oApp = new Outlook.Application(); // Get the NameSpace and Logon information. Outlook.NameSpace oNS = oApp.GetNamespace("mapi"); // Log on by using a dialog box to choose the profile. oNS.Logon(null, null, true, true); // Create a new mail item. Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); // Set the subject. oMsg.Subject = "Send Using OOM in C#"; // Set HTMLBody. String sHtml; sHtml = "<HTML>\n" + "<HEAD>\n" + "<TITLE>Sample GIF</TITLE>\n" + "</HEAD>\n" + "<BODY><P>\n" + "<h1><Font Color=Green>Inline graphics</Font></h1></P>\n" + "</BODY>\n" + "</HTML>"; oMsg.HTMLBody = sHtml; // Add a recipient. Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("[email protected]"); oRecip.Resolve(); // Send. oMsg.Display(); // Log off. oNS.Logoff(); // Clean up. oRecip = null; oRecips = null; oMsg = null; oNS = null; oApp = null;




Reply With Quote