|
-
Jul 26th, 2007, 12:57 PM
#1
Thread Starter
Fanatic Member
[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;
-
Jul 26th, 2007, 01:01 PM
#2
Thread Starter
Fanatic Member
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.
-
Jul 31st, 2007, 08:42 AM
#3
Thread Starter
Fanatic Member
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.
-
Aug 1st, 2007, 09:57 AM
#4
Frenzied Member
Re: [2.0] Send Email
I just use oMsg.Show().. i believe that should work..
-
Aug 1st, 2007, 11:24 AM
#5
Thread Starter
Fanatic Member
Re: [2.0] Send Email
Unfortunately, it looks like .Show is not an option with VS2005 2.0 C#. Any other ideas?
-
Aug 2nd, 2007, 05:41 AM
#6
Registered User
-
Aug 2nd, 2007, 06:50 AM
#7
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|