Click here to Skip to main content
Click here to Skip to main content

A Web based SMTP client program

By , 13 Sep 2001
 

Introduction

This is a web based SMTP email program. This program can be used to send an email through a SMTP server. The user can specify a SMTP server's IP, sender's mail address, recipient's email address and mail content. When the user clicks on the "send mail" button , the mail is forwarded to the SMTP server which in turn forwards the mail to the recipient.

Details

This SMTP mail program is for .NET beta 2. I have written a SMTP email component in C# and compiled it into a dll. Then this dll is accessed through an aspx file which can be viewed in a browser.

Note: There is built in SMTP class already available in System.Web.Mail namespace . However it is worth taking a look at program below as it shows inner details of how to communicate with a SMTP server. Once you grasp this technique, you can modify it to communicate with any TCP socket server like FTP (for file access), HTTP (for web access), IRC (for chat) etc.

First I'll give the  source to the SMTP mail client.

/******************SMTPMail.cs ************ 
Name : SMTPMail.cs
Description : SMTP email client .
 Version : 1.0
 Author : Ravindra Sadaphule
  Email : ravi_sadaphule@hotmail.com
  Last Modified: 13th September , 2001
  To compile: csc /t:library /out:SMTPMail.dll SMTPMail.cs
  Note : save this file in c:/inetpub/wwwroot/bin directory
  */
namespace Ravindra
{
    /* SMTPClient is a class which inherits from TcpClient . Hence it can 
    access all protected and public membert of TcpClient
    */
public class SMTPClient : System.Net.Sockets.TcpClient
{
    public bool isConnected()
    {
        return Active ;
    }

    public void SendCommandToServer(string Command)
    {
        System.Net.Sockets.NetworkStream ns = this.GetStream() ;
        byte[] WriteBuffer ;
        WriteBuffer = new byte[1024] ;
        System.Text.ASCIIEncoding en = new System.Text.ASCIIEncoding() ;
        WriteBuffer = en.GetBytes(Command) ;
        ns.Write(WriteBuffer,0,WriteBuffer.Length);
        return ; 
    }

    public string GetServerResponse()
    {

        int StreamSize ;
        string ReturnValue = "" ;
        byte[] ReadBuffer ;
        System.Net.Sockets.NetworkStream ns = this.GetStream() ;
        ReadBuffer = new byte[1024] ;
        StreamSize = ns.Read(ReadBuffer,0,ReadBuffer.Length);
        if (StreamSize==0)
        {
            return ReturnValue ;
        }
        else
        {
            System.Text.ASCIIEncoding en = new System.Text.ASCIIEncoding() ;
            ReturnValue = en.GetString(ReadBuffer) ;
            return ReturnValue;
        }
    }

    public bool DoesStringContainSMTPCode(System.String s,System.String SMTPCode)
    {
        return (s.IndexOf(SMTPCode,0,10)==-1)?false:true ;
    }

 }// end of class SMTPClient



public class SMTPMail
{
    private System.String _SMTPServerIP = "127.0.0.1" ;
    private System.String _errmsg = "" ;
    private System.String _ServerResponse = "" ;
    private System.String _Identity = "expowin2k" ;
    private System.String _MailFrom = "" ;
    private System.String _MailTo = "" ;
    private System.String _MailData = "" ;
    private System.String _Subject = "" ;

    public System.String Subject // This property contains Subject of email
    {
        set
        {
            _Subject = value ;
        }
    }

    public System.String Identity // This property contains Sender's Identity
    {
        set
        {
            _Identity = value ;
        }
    }

    public System.String MailFrom // This property contains sender's email address
    {
        set
        {
            _MailFrom = value ;
        }
    }

    public System.String MailTo // This property contains recepient's email address
    {
        set
        {
            _MailTo = value ;
        }
    }

    public System.String MailData // This property contains email message
    {
        set
        {
            _MailData = value ;
        }
    }

    public System.String SMTPServerIP // This property contains of SMTP server IP
    {
        get
        {
            return _SMTPServerIP ;
        }
        set
        {
            _SMTPServerIP = value ;
        }
    }

    public System.String ErrorMessage // This property contais error message
    {
        get
        {
            return _errmsg ;
        }
    }

    public System.String ServerResponse // This property contains  server response
    {
        get
        {
            return _ServerResponse ;
        }
    }

    public void SendMail()
    {
        try
        {
            System.String ServerResponse ;
            SMTPClient tcp = new SMTPClient() ; 
            tcp.Connect(SMTPServerIP,25) ; // first connect to smtp server
            bool blnConnect = tcp.isConnected();

            // test for successful connection
            if (!blnConnect)
            {
                _errmsg = "Connetion Failed..." ;
                return; 
                                                        }

            //read response of the server 
            ServerResponse = tcp.GetServerResponse() ;
            if (tcp.DoesStringContainSMTPCode(ServerResponse,"220"))
            {
                _ServerResponse += ServerResponse ;
            }
            else
            {
                _errmsg = "connection failed" + ServerResponse ; 
                 return ;
            }
            System.String[] SendBuffer = new System.String[6] ;;
            System.String[] ResponseCode = {"220","250","251","354","221"}; 

            System.String StrTemp = "" ;
            StrTemp = System.String.Concat("HELO ",_Identity);
            StrTemp = System.String.Concat(StrTemp,"\r\n");
            SendBuffer[0] = StrTemp ;
            StrTemp = "" ;
            StrTemp = System.String.Concat("MAIL FROM: ",_MailFrom);
            StrTemp = System.String.Concat(StrTemp,"\r\n");
            SendBuffer[1] = StrTemp ;

            StrTemp = "" ;
            StrTemp = System.String.Concat("RCPT TO: ",_MailTo);
            StrTemp = System.String.Concat(StrTemp,"\r\n");
            SendBuffer[2] = StrTemp ;

            StrTemp = "" ;
            StrTemp = System.String.Concat("DATA","\r\n");
            SendBuffer[3] = StrTemp ;

            StrTemp = "" ;
            StrTemp = System.String.Concat("From: ",_MailFrom );
            StrTemp = System.String.Concat(StrTemp,"\r\n" );
            StrTemp = System.String.Concat(StrTemp,"To: " );
            StrTemp = System.String.Concat(StrTemp,_MailTo);
            StrTemp = System.String.Concat(StrTemp,"\r\n" );
            StrTemp = System.String.Concat(StrTemp,"Subject: " );
            StrTemp = System.String.Concat(StrTemp,_Subject);
            StrTemp = System.String.Concat(StrTemp,"\r\n" );

            StrTemp = System.String.Concat(StrTemp,_MailData);
            StrTemp = System.String.Concat(StrTemp,"\r\n.\r\n");
            SendBuffer[4] = StrTemp ;

            StrTemp = "" ;
            StrTemp = System.String.Concat(StrTemp,"QUIT\r\n");
            SendBuffer[5] = StrTemp ;

            int i = 0 ;
            /* for debugging
            _errmsg = "" ;
            for(i=0;i<5;i++)
            {
                _errmsg += SendBuffer[i] ;
                += "<br>" ;
            }
            return ;
            // end of debugging
            */

            while(i < SendBuffer.Length)
             {
                tcp.SendCommandToServer(SendBuffer[i]) ; 
                ServerResponse = tcp.GetServerResponse() ;
                for(int j=0;j<ResponseCode.Length;j++)
                {
                    if (tcp.DoesStringContainSMTPCode(ServerResponse,ResponseCode[j]))
                        {
                            _ServerResponse += ServerResponse;
                            _ServerResponse += "<br>";
                            break;
                        }
                    else
                    {
                        if(j==ResponseCode.Length-1)
                        {
                            _errmsg += ServerResponse ;
                                _errmsg += SendBuffer[i] ;
                            return ;
                        }
                    }
                }

                i++ ;
             } // end of while loop ;

        }// end of try block
        catch(System.Net.Sockets.SocketException se)
        {
            _errmsg += se.Message + " " + se.StackTrace;
        }
        catch(System.Exception e)
        {
            _errmsg += e.Message + " " + e.StackTrace;
        }
    } // end of SendMail method

 } // end of class client

 } // end of namespace Ravindra

 /*****************end of Modified SMTPMail.cs*********/

The program is big but quite simple . A class SMTPClient is derived from TcpClient . Hence all protected and public properties of TcpClient are available to SMTPClient class.

Now go directly to SendMail class. In this class I have added several private variables and corresponding properties like smtpserverIP, MailFrom, MailTo etc. These properties are set by the smtpMail.aspx program which is given below.

Property   

Description

Identity:   

This is identity of sender e.g. ravindra

MailFrom:   

Sender's email address e.g. ravindra@hotmail.com

MailTo:   

Recepient's email address

Subject:   

Topic of Mail

MailData:   

mail contents

SMTPServerIP:   

IP address of SMTP server


All these inputs are received from smtpMail.aspx file. In the SendMail() method of SMTPMail class an instance of SMTPClient class is created and connection to smtp server is attempted .The blnconnect flag indicates success/failure connection. If a connection fails, then an error message is generated and the program Terminates. 

On a successful connection (i.e. blnconnect is true) , the SMTP server's response is analyzed for success code "220". If SMTP responds with success code "220", then the action starts.

All SMTP commands are stored in array SendBuffer[] . All possible success codes from the SMTP server are stored in an array ResponseCode[]. So the commands from the array SendBuffer[] are sent to the SMTP server one by one and for each command the response from the SMTP server is analysed by comparing the SMTP server reply code with any of the possible success codes in the ResponseCode array. If the command executes successfully then only the next command is attempted. If any of commands is unsuccessful, then an error message is generated and the program terminates immediately.

Compile this smtpmail.cs file and put it into the c:/inetpub/wwwroot/bin directory.

Web based front end is given below. SMTPMail.aspx is put into c:\inetpub\wwwroot directory which is configured as the default website in IIS. This page can be viewed in browser by Typing url http://localhost/SMTPMAil.aspx.  The page shows some textboxes to capture input data like SMTP server ip ,sender's email , recepient;s email, subject, Mail Data etc. and a "Send Mail" button .

When user enters data into the textboxes and clicks on the "send Mail" button , a function btnSend_Click() is called. In this function  an instance of the SMTPMail class is created. Please remember that this SMTPMail class has been defined in the SMTPMAIL.cs file. Iin btnSend_Click() we capture inputs from user and set various properties of smail (an instance of SMTPMail) and call its sendmail() method.

If everything is OK , then a message "Mail Has been sent successfully" is displayed at the top of the page. If any error occurs, then an error message is displayed at the top.

<%@ Import NameSpace="Ravindra" %>
<script language="C#" runat="server">
void btnSend_Click(Object Sender,EventArgs e)
{
    if(Page.IsPostBack)
    {
        SMTPMail smail = new SMTPMail() ; ;
        smail.MailFrom = txtfrom.Text ;
        smail.MailTo = txtto.Text  ;
        smail.MailData = txtmessage.Text ;
        smail.Subject = txtSubject.Text ;
        smail.SMTPServerIP = txtSMTPServerIP.Text ;
        smail.SendMail();
        if (smail.ErrorMessage!="")
        {
            Response.Write("Error: " + smail.ErrorMessage) ;
        }
        else
        {
            /*
                for debugging only.
                    Response.Write(smail.ServerResponse + "Mail Sent successfully") ;
            */
            Response.Write("<br>Mail Sent successfully<br>") ; 
       }
    }
}

</script>
<html>
    <head>
        <title>SMTP E-Mail Example by Ravindra Sadaphule </title>
    </head>
    <body>
        <form name="frm1" runat="server" id="Form1">
            <table width="100%">
                <tr>
                    <td colspan="2" align="center">
                        <h3>
                            SMTP MAIL
                        </h3>
                    </td>
                </tr>
                <tr>
                    <td width="30%" align="center" valign="middle">
                        SMTP SERVER IP:
                    </td>
                    <td width="70%" align="left" valign="middle">
                        <asp:textbox id="txtSMTPServerIP" runat="server" />
                        e.g. 127.0.0.1
                    </td>
                </tr>
                <tr>
                    <td width="30%" align="center" valign="middle">
                        From:
                    </td>
                    <td width="70%" align="left" valign="middle">
                        <asp:textbox id="txtfrom" runat="server" />
                        e.g. ravi_sadaphule@hotmail.com
                    </td>
                </tr>
                <tr>
                    <td width="30%" align="center" valign="middle">
                        To:
                    </td>
                    <td width="70%" align="left" valign="middle">
                        <asp:textbox id="txtto" runat="server" />
                        e.g. tarunt@bharat.com
                    </td>
                </tr>
                <tr>
                    <td width="30%" align="center" valign="middle">
                        Sub:
                    </td>
                    <td width="50%" align="left" valign="middle">
                        <asp:textbox id="txtSubject" runat="server" />
                        e.g. Marriage Proposal
                    </td>
                </tr>
                <tr>
                    <td width="30%" align="center" valign="middle">
                        Message:
                    </td>
                    <td width="70%" align="left" valign="middle">
                        <asp:textbox id="txtmessage" textmode="MultiLine" rows="5" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td width="30%" align="center" valign="middle">
                         
                    </td>
                    <td width="70%" align="left" valign="middle">
                        <asp:button text="Send Mail" id="btnSend" onclick="btnSend_Click" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td width="30%" align="center" valign="middle">
                         
                    </td>
                    <td width="70%" align="left" valign="middle">
                        Developer:  <a href="mailto:ravi_sadaphule@hotmail.com">Ravindra Sadaphule</a>
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>

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

Ravindra Sadaphule
Web Developer
India India
Member
MCSD.NET IT Professional with over 11 years of experience.Worked at various levels as Business Analyst, Technical Architect, System Analyst and Developer.
 

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.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralSMTPmemberRamez Quneibi16 Jul '07 - 7:42 
Hi
Great project, but I have problems with sending an email using my localhost (127.0.0.1), I am trying to send an email to my account on yahoo server. I sent the email many times and i saw the antivirus while it is scanning the email, then I go to check my email and i didnt find any received emails.
could you please help me !!??
 
I hope that i am helping programmers

GeneralRe: SMTPmemberasoft-consulting20 May '08 - 6:22 
Yahoo doesn't allow mail from dymanic IPs as it considers mail from these addresses to be spam. Try sending the same mail from a server with a static IP.
QuestionAddress DebuggingmemberThe .Net Learner27 Jun '06 - 11:37 
Great Class Smile | :)
 
Can you suggest a way to check the validity of an e-mail address without actually sending mail to it(VRFY)...
 

Thanks in advance.
Generalusing another mail server in ASP.NETsussPoonam G6 Mar '05 - 0:25 
how can i use mail server other than SMTP for sending mail from an ASP.NET application.Can anyone send me a code ?
GeneralMultiple recipientssussAnonymous23 Aug '04 - 3:24 
I'm using an ini file for an email to list. I tried using semicolon and comma to seperate the recipients but always get invalid address error. Is this accounted for in the code or do I need to create a loop?
GeneralRe: Multiple recipientsmemberNir Levy1 Feb '05 - 21:44 
Repeat the RCPT TO for each recipient.
 
Note that this is not very wise thing to do the way the program is written now becuase if one of the recipients fail all of them will fail. You should re-write the relevant error handling functions and support partial failures.

 
best regards
/NL
 
polynr69 at gmail dot com
GeneralNice worksussAnonymous24 May '04 - 9:44 
Very good piece of code with the authorization part added.
 
Saved me alot of work. Thanks
QuestionSend HTML fromat email?memberllj16 Mar '04 - 16:43 
Confused | :confused:
What to do?
AnswerRe: Send HTML fromat email?memberbkg421110 Apr '04 - 18:11 
Posted this to another thread on this article, but I believe the answer also resolves your question.
 
The SMTP protocol specifies that attachments are handled using multi-part mime encoding of the "payload" of the SMTP packet.
 
Each mime-part (piece of content in the message) must include a MIME-type (i.e. content type). I believe that my sending a multi-part mime message with a single mime-part whose MIME-type is text/html you will have sent a legitimate HTML mail.
 
You would need to learn how to properly format a mutli-part MIME message. There are numerous examples of how to do this out on the web.
 
Try looking at the docs for the .net file upload HTML Control. HTTP file posting also happens to use multi-part MIME encoding.
GeneralAtachmentmembermarcin99722 Feb '04 - 22:50 
Hello !
How to add support for attachment for this excellent SMTP Class?
 
Regards,
MArcin
GeneralRe: Atachmentmemberbkg421110 Apr '04 - 18:07 
The SMTP protocol specifies that attachments are handled using multi-part mime encoding of the "payload" of the SMTP packet.
 
You would need to learn how to properly format a mutli-part MIME message. There are numerous examples of how to do this out on the web.
 
Try looking at the docs for the .net file upload HTML Control. HTTP file posting also happens to use multi-part MIME encoding.
GeneralReturn_Path SettingmemberCurious Person26 Sep '03 - 1:24 
Hi,
 
Do you know how to set the Return-Path address different from Reply-To address? I need to set Return-Path to a dummy address for bounced emails which is transparent to sender but I also need the Reply-To to the correct sender's address. Please help! Thanks!
QuestionCan I use c compiler or C++ compiler to compilememberkarlim24 Jul '03 - 22:49 
Dear Mr Ravindra Sadaphule,
 
Thank you for your source code of SMTP component that you public in
codeproject.com.
I have some question to ask you. If I want to use Visual Basic to develop
the SMTP component like What you write. It is possible?
I don't have crc compiler, Can I use c compiler or C++ compiler to compile
your source code?
 
Thank you for read my mail.

Generalvb.netmemberframail2 May '03 - 6:52 
i wrote a vb.net to use this class. but the error msg "553 sorry, your envelope sender domain must exist (#5.7.1). any idea? Frown | :(
GeneralStep by stepsussAnonymous19 Apr '03 - 5:38 
First Of all I would like to thank you for your hard work to teach us some basic programmer languge. Thanks again Smile | :) .
 
Could you please help me and other's who are same level in "New Technology" programmer.
 
I would like if you please explain for us what to do in each step {Step by step} with screenshot. Iam I really love to learn how to setup smtp/web email but i don't know how to do that .
 
Thanks Alot'sCry | :(( Cry | :((
GeneralWeb based SMTP clientsussAnonymous21 Feb '03 - 2:46 
Excellent Job
GeneralProblem sending mailsmemberahpex12 Jan '03 - 6:42 
Hi,
 
a very useful class Smile | :) , but following problem occurs:
When sending mails in a loop like this
 

SMTPMail smail = new SMTPMail();
 
for (int i = 1; i <= 100; i++)
{
// assignments here
smail.MailTo = "customer@customer.com";
...
 
smail.SendMail();
}

a message appears, saying that the connection has failed due to a faulty connection or that the data has been send too fast, so the SMTP server is unable to process it.
The first mail (i = 1) is always delivered, so I don't think its a faulty connection.
 
How can I solve this?
 
bye,
Ahpex
 


GeneralRe: Problem sending mailsmemberjulesr23 May '03 - 8:48 
Try putting all you code inside of the loop. eg
 
for (int i = 1; i <= 100; i++)
{
SMTPMail smail = new SMTPMail();
// assignments here
smail.MailTo = "customer@customer.com";
...
 
smail.SendMail();
}

QuestionWhat if the smtp server requires authentication?memberAnonymous19 Dec '02 - 23:21 
If relaying is not allowed in a particular smtp server, then the user should be authenticated to send the mail thru' that smtp server. How can we achieve this?
AnswerRe: What if the smtp server requires authentication?memberwebxiao28 Mar '03 - 19:57 
//these support authentication
//welcome to my web: www.dotnet.cn
 

namespace AspNetForums.Components
{
/* SMTPClient is a class which inherits from TcpClient . Hence it can
access all protected and public membert of TcpClient
*/
public class SMTPClient : System.Net.Sockets.TcpClient
{
public bool isConnected()
{
return Active ;
}
 
public void SendCommandToServer(string Command)
{
System.Net.Sockets.NetworkStream ns = this.GetStream() ;
byte[] WriteBuffer ;
WriteBuffer = new byte[1024] ;
System.Text.ASCIIEncoding en = new System.Text.ASCIIEncoding() ;
WriteBuffer = en.GetBytes(Command) ;
ns.Write(WriteBuffer,0,WriteBuffer.Length);
return ;
}
 
public string GetServerResponse()
{
 
int StreamSize ;
string ReturnValue = "" ;
byte[] ReadBuffer ;
System.Net.Sockets.NetworkStream ns = this.GetStream() ;
ReadBuffer = new byte[1024] ;
StreamSize = ns.Read(ReadBuffer,0,ReadBuffer.Length);
if (StreamSize==0)
{
return ReturnValue ;
}
else
{
System.Text.ASCIIEncoding en = new System.Text.ASCIIEncoding() ;
ReturnValue = en.GetString(ReadBuffer) ;
return ReturnValue;
}
}
 
public bool DoesStringContainSMTPCode(System.String s,System.String SMTPCode)
{
return (s.IndexOf(SMTPCode,0,10)==-1)?false:true ;
}
 
}// end of class SMTPClient
 

 
public class SMTPMail
{
private System.String _SMTPServerIP = "127.0.0.1" ;
private System.String _errmsg = "" ;
private System.String _ServerResponse = "" ;
private System.String _Identity = "expowin2k" ;
private System.String _MailFrom = "" ;
private System.String _MailTo = "" ;
private System.String _MailData = "" ;
private System.String _Subject = "" ;
private System.String _Password="";
 
public System.String Subject // This property contains Subject of email
{
set
{
_Subject = value ;
}
}
 
public System.String Identity // This property contains Sender's Identity
{
set
{
_Identity = value ;
}
}
 
public System.String MailFrom // This property contains sender's email address
{
set
{
_MailFrom = value ;
}
}
 
public System.String MailTo // This property contains recepient's email address
{
set
{
_MailTo = value ;
}
}
 
public System.String MailData // This property contains email message
{
set
{
_MailData = value ;
}
}
 
public System.String SMTPServerIP // This property contains of SMTP server IP
{
get
{
return _SMTPServerIP ;
}
set
{
_SMTPServerIP = value ;
}
}
 
public System.String ErrorMessage // This property contais error message
{
get
{
return _errmsg ;
}
}
 
public System.String ServerResponse // This property contains server response
{
get
{
return _ServerResponse ;
}
}
 
public System.String Password
{
set
{
_Password=value;
}
}
 
public void SendMail()
{
try
{
System.String ServerResponse ;
SMTPClient tcp = new SMTPClient() ;
tcp.Connect(SMTPServerIP,25) ; // first connect to smtp server
bool blnConnect = tcp.isConnected();
 
// test for successful connection
if (!blnConnect)
{
_errmsg = "Connetion Failed..." ;
return;
}
 
//read response of the server
ServerResponse = tcp.GetServerResponse() ;
if (tcp.DoesStringContainSMTPCode(ServerResponse,"220"))
{
_ServerResponse += ServerResponse ;
}
else
{
_errmsg = "connection failed" + ServerResponse ;
return ;
}
System.String[] SendBuffer = new System.String[9];
System.String[] ResponseCode = {"220","334","235","250","251","354","221"};
 
System.String StrTemp = "" ;
StrTemp = System.String.Concat("HELO ",_Identity);
StrTemp = System.String.Concat(StrTemp,"\r\n");
SendBuffer[0] = StrTemp ;
 
//验证
StrTemp="";
StrTemp=System.String.Concat("AUTH LOGIN","\r\n");
SendBuffer[1]=StrTemp;
//用户名
StrTemp="";
string EncodedFrom = System.Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(_MailFrom));
StrTemp=System.String.Concat(EncodedFrom,"\r\n");
SendBuffer[2]=StrTemp;
//密码
StrTemp="";
string EncodedPass =System.Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(_Password));
StrTemp=System.String.Concat(EncodedPass,"\r\n");
SendBuffer[3]=StrTemp;
 
StrTemp = "" ;
StrTemp = System.String.Concat("MAIL FROM: ",_MailFrom);
StrTemp = System.String.Concat(StrTemp,"\r\n");
SendBuffer[4] = StrTemp ;
 
StrTemp = "" ;
StrTemp = System.String.Concat("RCPT TO: ",_MailTo);
StrTemp = System.String.Concat(StrTemp,"\r\n");
SendBuffer[5] = StrTemp ;
 
StrTemp = "" ;
StrTemp = System.String.Concat("DATA","\r\n");
SendBuffer[6] = StrTemp ;
 
StrTemp = "" ;
StrTemp = System.String.Concat("From: ",_MailFrom );
StrTemp = System.String.Concat(StrTemp,"\r\n" );
StrTemp = System.String.Concat(StrTemp,"To: " );
StrTemp = System.String.Concat(StrTemp,_MailTo);
StrTemp = System.String.Concat(StrTemp,"\r\n" );
StrTemp = System.String.Concat(StrTemp,"Subject: " );
StrTemp = System.String.Concat(StrTemp,_Subject);
StrTemp = System.String.Concat(StrTemp,"\r\n" );
 
StrTemp = System.String.Concat(StrTemp,_MailData);
StrTemp = System.String.Concat(StrTemp,"\r\n.\r\n");
SendBuffer[7] = StrTemp ;
 
StrTemp = "" ;
StrTemp = System.String.Concat(StrTemp,"QUIT\r\n");
SendBuffer[8] = StrTemp ;
 
int i = 0 ;
/* for debugging
_errmsg = "" ;
for(i=0;i<5;i++)
{
_errmsg += SendBuffer[i] ;
+= "
" ;
}
return ;
// end of debugging
*/
 
while(i < SendBuffer.Length)
{
tcp.SendCommandToServer(SendBuffer[i]) ;
ServerResponse = tcp.GetServerResponse() ;
for(int j=0;j break;
}
else
{
if(j==ResponseCode.Length-1)
{
_errmsg += ServerResponse ;
_errmsg += SendBuffer[i] ;
return ;
}
}
}
 
i++ ;
} // end of while loop ;
 
}// end of try block
catch(System.Net.Sockets.SocketException se)
{
_errmsg += se.Message + " " + se.StackTrace;
}
catch(System.Exception e)
{
_errmsg += e.Message + " " + e.StackTrace;
}
} // end of SendMail method
 
} // end of class client
 
} // end of namespace Ravindra
 
/*****************end of Modified SMTPMail.cs*********/
GeneralIt's cool. Smtp class in .Net is not goodsusskon_n14 Aug '02 - 1:39 
I had some problem when I used Smtp class because it support only Windows 2000, Windows XP Professional and Windows .NET Server family Platforms.

GeneralRe: It's cool. Smtp class in .Net is not goodmemberDaniel Turini14 Aug '02 - 1:51 
You could always try ATL's CSMTPConnection.
Unfortunately, it's not clearly documented which platforms it supports.
 

Concussus surgo.
When struck I rise.

GeneralRe: It's cool. Smtp class in .Net is not goodeditorJames T. Johnson14 Aug '02 - 2:28 
Considering those are the supported platforms for ASP.NET and this class is meant for ASP.NET (as is the Smtp class provided by .NET) that makes sense.
 
James
"And we are all men; apart from the females." - Colin Davies
GeneralRe: It's cool. Smtp class in .Net is not goodmemberMatt Newman11 Feb '04 - 9:45 
kon_n wrote:
I had some problem when I used Smtp class because it support only Windows 2000, Windows XP Professional and Windows .NET Server family Platforms.
 
I don't know of any other platforms that support IIS 5.1 or greater and ASP.NET
 
Matt Newman
 

GeneralCoolmemberJaish26 Jun '02 - 3:31 
The article was really cool..keep up the good job....and do keep posting such interesting .net articles...
 
Regards,
Jaish
Generalooppss....Got Problem with codememberHussain26 May '02 - 21:02 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
 
Compiler Error Message: CS1513: } expected
 
Source Error:
 

 
Line 28: }
Line 29:
Line 30: }
Line 31:
Line 32: </script>

 
Source File: C:\Inetpub\wwwroot\SMTPMail\SmtpMail.aspx Line: 30
 

Any Idea...
 
Smile
Sajid
 
Hussain
GeneralRe: ooppss....Got Problem with codememberwengwb21 Mar '03 - 13:40 
please compile the cs file first. then put it under /bin.Smile | :)
QuestionSmtpMail class?!?memberkrypta8 Apr '02 - 6:03 
why you don't use the smtpmail-class provided by the .net framework?!?
 
best rgds
AnswerRe: SmtpMail class?!?memberSoliant10 Sep '02 - 10:37 
I agree, why not use what Microsoft.NET offers?
 
Don't reinvent the wheel Smile | :)

 




Soliant | email
 
"the result is that VC7 is the only compiler to generate optimized MSIL" - Stanley Lippman

GeneralRe: SmtpMail class?!?membercacadweqe21e22 Oct '03 - 1:31 
Because it only works on Win2k/XP not in win9x, because microsofts classes uses CDO for Windows 2000 in the background, which doesnt exists in win9x Smile | :)
GeneralRe: SmtpMail class?!?memberY4U7J421 Mar '04 - 21:50 
another factor is you cannot use System.Web.Mail to access a smtp server which requires authentication. you should write your own code. one is using CDO, or work with sockets.
AnswerRe: SmtpMail class?!?sussDegan1 Nov '02 - 13:53 
Because the .Net class is very limited. It is missing quite a few things. Like embedded Inline images etc...OMG | :OMG: Eek! | :eek:
AnswerRe: SmtpMail class?!?sussAnonymous25 Sep '03 - 7:44 
Document Quote "Note: There is built in SMTP class already available in System.Web.Mail namespace . However it is worth taking a look at program below as it shows inner details of how to communicate with a SMTP server"
 
Fellows, we all know there's a built-in SMTP class in .NET, I believe the author wrote this code with more of an educative purpose.
 
So please stop posting stupid comments.
 
Steve,
QuestionSMTP,poxy -Hiding Original IP address-anybody have any idea?memberHirosh Joseph26 Feb '02 - 15:28 
Some email utility senting mails that hides the IP address using a proxy server example
http://mailinglistmaster.com/index.cfm?action=proxylist
anybody have any idea what thay doing or which protocol they using?
hirosh

Generalvery coolmemberFilip Govaerts16 Sep '01 - 1:22 
This article show once more the power of dotnet(and what a skilled programmer can do with it Poke tongue | ;-P ).
great job!
GeneralRe: very coolmemberAnonymous9 Oct '01 - 20:40 
Itz interesting to work with .Net. U have done a good job. Keep it up.
Rose | [Rose] Rose | [Rose] Rose | [Rose] Rose | [Rose]
 
Sreedhar Reddy

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 14 Sep 2001
Article Copyright 2001 by Ravindra Sadaphule
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid