Results 1 to 7 of 7

Thread: [2.0] Send Email

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    [2.0] Send Email

    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 If
    Code:
    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;

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    Re: [2.0] Send Email

    Actually, I found the problem. I misspelt the email but while I have your attention, does anyone know how to use the oMsg.Display()? I believe it needs something in the brackets but I do not know what.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    Re: [2.0] Send Email

    Bump. Anyone use oMsg.Display? There must be some way to display the email and then have the user send it.

  4. #4
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407

    Re: [2.0] Send Email

    I just use oMsg.Show().. i believe that should work..

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    Re: [2.0] Send Email

    Unfortunately, it looks like .Show is not an option with VS2005 2.0 C#. Any other ideas?

  6. #6
    Registered User RaviIntegra's Avatar
    Join Date
    Mar 2007
    Location
    Pondicherry, India
    Posts
    125

    Re: [2.0] Send Email


  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    Re: [2.0] Send Email

    I do not have access to SMTP.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width