MailMessage

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike P

    #1

    MailMessage

    Can the MailMessage class be used to send emails from a machine that has
    no email account (such as Outlook)?


    Mike



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Tomas Vera

    #2
    Re: MailMessage

    Mike P wrote:
    [color=blue]
    > Can the MailMessage class be used to send emails from a machine that has
    > no email account (such as Outlook)?
    >[/color]

    I've not used this, but it looks like you would also need the
    System.Web.Mail .SmtpMail class to do the actual transporting of the mail.
    That class contains a SmtpServer member which is the name of the server to
    relay the message. So (from the description), you should be able to compose
    and send an e-mail message with little trouble.

    --
    /*-------------------------------------
    * Tomas Vera
    * tavera@sbcgloba l.net
    * tomas.vera@tape ware.com
    *-----------------------------------*/

    Comment

    • Christopher Dundon

      #3
      Re: MailMessage

      It is capable of doing so, but you will have to declare
      the SMTP server. Tomas Vera touched on that in his
      response, here's a snippet of code I use in a program to
      send an email which works great.

      /// <summary>
      /// Sends an email using the SMTP service.
      /// </summary>
      /// <param name="sServer"> SMTP server to send to</param>
      /// <param name="sFrom">Em ail sending from</param>
      /// <param name="sTo">Emai l sending to</param>
      /// <param name="sSubject" >Subject of the email</param>
      /// <param name="sBody">Bo dy of the email</param>
      /// <returns>True if sent successfully, false if an error
      occured</returns>
      public bool SMTPSend(string sServer, string sFrom, string
      sTo, string sSubject, string sBody)
      {
      try
      {
      // Build the MailMessage object
      MailMessage oMessage = new MailMessage();
      oMessage.From = sFrom;
      oMessage.To = sTo;
      oMessage.Subjec t = sSubject;
      oMessage.Body = sBody;

      // Set the SMTP server and send the
      message.
      SmtpMail.SmtpSe rver = sServer;
      SmtpMail.Send(o Message);

      // If we got this far, it was sent
      successfully.
      return true;
      }
      catch
      {
      // An error occured, so return false
      instead.
      return false;
      }
      }

      Hope this helps!

      - Chris
      [color=blue]
      >-----Original Message-----
      >Can the MailMessage class be used to send emails from a[/color]
      machine that has[color=blue]
      >no email account (such as Outlook)?
      >
      >
      >Mike
      >
      >
      >
      >*** Sent via Developersdex http://www.developersdex.com[/color]
      ***[color=blue]
      >Don't just participate in USENET...get rewarded for it!
      >.
      >[/color]

      Comment

      • Champika Nirosh

        #4
        Re: MailMessage

        Hi All,

        System..Mail namespace uses CDO (Colleborate Data Object) SYS which come
        with out look (if I am correct it won't work with win 98) so if you need to
        avoid that, you may have to write the send method from the scratch.. I saw
        there are samples on the web discribes how to send mail without CDO SYS

        Nirosh.

        "Christophe r Dundon" <nighthawk@theh ouseofchris.net > wrote in message
        news:0c8501c34c 89$0f88cd00$a60 1280a@phx.gbl.. .[color=blue]
        > It is capable of doing so, but you will have to declare
        > the SMTP server. Tomas Vera touched on that in his
        > response, here's a snippet of code I use in a program to
        > send an email which works great.
        >
        > /// <summary>
        > /// Sends an email using the SMTP service.
        > /// </summary>
        > /// <param name="sServer"> SMTP server to send to</param>
        > /// <param name="sFrom">Em ail sending from</param>
        > /// <param name="sTo">Emai l sending to</param>
        > /// <param name="sSubject" >Subject of the email</param>
        > /// <param name="sBody">Bo dy of the email</param>
        > /// <returns>True if sent successfully, false if an error
        > occured</returns>
        > public bool SMTPSend(string sServer, string sFrom, string
        > sTo, string sSubject, string sBody)
        > {
        > try
        > {
        > // Build the MailMessage object
        > MailMessage oMessage = new MailMessage();
        > oMessage.From = sFrom;
        > oMessage.To = sTo;
        > oMessage.Subjec t = sSubject;
        > oMessage.Body = sBody;
        >
        > // Set the SMTP server and send the
        > message.
        > SmtpMail.SmtpSe rver = sServer;
        > SmtpMail.Send(o Message);
        >
        > // If we got this far, it was sent
        > successfully.
        > return true;
        > }
        > catch
        > {
        > // An error occured, so return false
        > instead.
        > return false;
        > }
        > }
        >
        > Hope this helps!
        >
        > - Chris
        >[color=green]
        > >-----Original Message-----
        > >Can the MailMessage class be used to send emails from a[/color]
        > machine that has[color=green]
        > >no email account (such as Outlook)?
        > >
        > >
        > >Mike
        > >
        > >
        > >
        > >*** Sent via Developersdex http://www.developersdex.com[/color]
        > ***[color=green]
        > >Don't just participate in USENET...get rewarded for it!
        > >.
        > >[/color][/color]


        Comment

        Working...