Click here to Skip to main content
Licence 
First Posted 12 Nov 2001
Views 71,070
Bookmarked 12 times

SendMail

By | 12 Nov 2001 | Article
Send Email using Command Line Parameters
using System;
using System.Web.Mail;

class SendMail
{
     static void Main(string[] args)
     {
          int Ctr = 0;  
          int ArgSw = 0;
          int ConcatSw = 0;
        
          try
          {  
               MailMessage Msg = new MailMessage();

               foreach (string Arg in args)

               {
                    ConcatSw = 0; 
                    Ctr = Ctr + 1;

                    if(Ctr == 1)
                    {  
                         Msg.To = Arg;
                    }

                    if(Ctr == 2)   
                    {       
                         Msg.From = Arg;
                    }

                    if(Ctr > 2)
                    {  
                         if(Arg.Equals("-s"))
                         {
                              ArgSw = 1;
                              ConcatSw = 1;
                         }  

                         if(Arg.Equals("-b"))
                         {
                              ArgSw = 2; 
                              ConcatSw = 1;
                         }  


                         if(ArgSw == 1 && ConcatSw == 0)
                         {
                              Msg.Subject = Msg.Subject + Arg + " ";      
                         }   

                         if(ArgSw == 2 && ConcatSw == 0)
                         {
                              Msg.Body = Msg.Body + Arg + " ";      
                         }   
                    }
               }

               SmtpMail.Send(Msg);
               Console.WriteLine("Ok");
          }
          catch
          {
               Console.WriteLine("Error");
               Console.WriteLine("SendMail [to@email.com] [from@email.com] -s [Subject] -b [Body]"); 
          } 
     }
}           

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Martin Castañeda



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralSMTP Authentication Support PinmemberDeepak Kumar Vasudevan0:30 5 Aug '03  
Generala PinsussAnonymous20:54 26 Feb '03  
QuestionWhat about setting the SMTP Server PinsussAnonymous8:00 11 Dec '02  
QuestionHow about receive mail Pinmemberhitheone3:05 1 Apr '02  
AnswerRe: How about receive mail PinmemberJon Sagara12:26 15 Jan '03  
GeneralRe: How about receive mail PinsussAnonymous23:06 18 Jan '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 13 Nov 2001
Article Copyright 2001 by Martin Castañeda
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid