Results 1 to 6 of 6

Thread: Send E-mail via Outlook - Stop Prompts?

  1. #1

    Thread Starter
    Hyperactive Member Pozzi's Avatar
    Join Date
    Feb 2001
    Location
    The Stones!
    Posts
    507

    Send E-mail via Outlook - Stop Prompts?

    Hi there,

    I've tried the following example to send an e-mail via Outlook and it works fine: -

    Code:
    using System;
    using System.Reflection;     // to use Missing.Value
    // TO DO: If you use the Microsoft Outlook 11.0 Object Library, uncomment the following line.
    //using Outlook = Microsoft.Office.Interop.Outlook;
    
    namespace SendHTMLMail
    {
    	public class Class1
    	{
    		public static int Main(string[] args)
    		{
    			try
    			{
    				// Create the Outlook application.
    				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(Missing.Value, Missing.Value, true, true);
    
    				// Alternate logon method that uses a specific profile.
    				// TODO: If you use this logon method,
    				//  change the profile name to an appropriate value.
    				//oNS.Logon("YourValidProfile", Missing.Value, false, 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;
    				// TODO: Change the recipient in the next line if necessary.
    				Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("someone@somewhere");
    				oRecip.Resolve();
    
    				// Send.
    				oMsg.Send();
    
    				// Log off.
    				oNS.Logoff();
    
    				// Clean up.
    				oRecip = null;
    				oRecips = null;
    				oMsg = null;
    				oNS = null;
    				oApp = null;
    			}
    
    				// Simple error handling.
    			catch (Exception e)
    			{
    				Console.WriteLine("{0} Exception caught.", e);
    			}
    
    			// Default return value.
    			return 0;
    
    		}
    	}
    }
    Although it works I am shown 2 dialog boxes from Outlook which I have to respond to.

    Is there a way to stop these from appearing, or another way to send an e-mail using C#?

    Regards
    VB.Net (VS 2010)

  2. #2
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    Re: Send E-mail via Outlook - Stop Prompts?

    I dont think you can disable these, for one obvious reason.
    Those prompts are there to prevent viruses using outlook to send email from your account.
    If you could disable it, then so could viruses.

    Why not send it using c# code?

    Woka

  3. #3

    Thread Starter
    Hyperactive Member Pozzi's Avatar
    Join Date
    Feb 2001
    Location
    The Stones!
    Posts
    507

    Re: Send E-mail via Outlook - Stop Prompts?

    Hi,

    Many thanks for the reply.

    Where can I find information or examples to send e-mails via C# code?

    Regards
    VB.Net (VS 2010)

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,430

    Re: Send E-mail via Outlook - Stop Prompts?

    For seemingly the hundredth time today, what version are you using? The answer is different in 1.x and 2.0. Please always specify the version you're using when creating a thread. There are radio buttons provided for the purpose.

  5. #5

    Thread Starter
    Hyperactive Member Pozzi's Avatar
    Join Date
    Feb 2001
    Location
    The Stones!
    Posts
    507

    Re: Send E-mail via Outlook - Stop Prompts?

    My apologies, but I failed to see those. I'm using 1.0/1.1.

    Anyway I've found an example http://www.codeproject.com/csharp/sendmailcsharp.asp which works.

    Regards
    VB.Net (VS 2010)

  6. #6
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,606

    Re: Send E-mail via Outlook - Stop Prompts?

    Quote Originally Posted by Pozzi
    My apologies, but I failed to see those. I'm using 1.0/1.1.

    Anyway I've found an example http://www.codeproject.com/csharp/sendmailcsharp.asp which works.

    Regards
    it would be significantly easier to send e-mails using the System.Web.Mail classes.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

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