Good Morning All

I have the Following code that sends an e-mail, let me first post the markup and the code behind. The following is the markup of my page

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        To &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<asp:TextBox ID="txtto" runat="server" Width="325px"></asp:TextBox><br />
        <br />
        From &nbsp;&nbsp; &nbsp;<asp:TextBox ID="txtFrom" runat="server" Width="326px"></asp:TextBox><br />
        &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
        <br />
        CC: &nbsp; &nbsp;&nbsp; &nbsp;<asp:TextBox ID="txtcc" runat="server" Width="326px"></asp:TextBox><br />
        <br />
        Subject:
        <asp:TextBox ID="txtsubject" runat="server" Width="326px"></asp:TextBox><br />
        Body :<br />
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;
        <asp:TextBox ID="txtbody" runat="server" Height="86px" Width="314px"></asp:TextBox><br />
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br />
        Port: &nbsp; &nbsp; &nbsp; &nbsp;
        <asp:TextBox ID="txtport" runat="server" Width="127px"></asp:TextBox><br />
        &nbsp;<br />
        Host &nbsp; &nbsp; &nbsp; &nbsp;
        <asp:TextBox ID="txthost" runat="server" Width="127px"></asp:TextBox><br />
        <br />
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<asp:Button ID="btnSend" runat="server"
            OnClick="btnSend_Click" Text="Send" />
        <asp:Button ID="btnCancel" runat="server" Text="Cancel" /><br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div>
    </form>
</body>
</html>

and i have a Function that sends the e-mail like this

private static string SendEmail(String from, string to, string cc,int port, string subject, string message,String Host)
    {
        //create the mail message
        System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
        //set the content
        mail.From = new System.Net.Mail.MailAddress(from,"Test E-mail");

        mail.Subject = subject;

        mail.Body = message;
        
        mail.IsBodyHtml = false;
        
        
        //send the message
        //SmtpClient smtp = new SmtpClient("196.35.193.28");     // use this Smtp Server
        // seems we can use either the big routing server or our own ip address
        System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
       
        smtp.Port = port;
        
        smtp.Host = Host;
         //mailSenderInstance.Credentials = New System.Net.NetworkCredential("LoginAccout", "Password") 
        smtp.Credentials = new System.Net.NetworkCredential("administrator", "skskssk");
 
        try
        {
            smtp.Send(mail);
            return "Mail sent successfully!";
        }
        catch (Exception ex)
        {
            Exception ex2 = ex;
        
            string errorMessage = string.Empty;

            while (ex2 != null)
            {
                errorMessage += ex2.ToString();
            
                ex2 = ex2.InnerException;
            }

            return errorMessage;
        }
        // Mailbox unavailable. The server response was 5.7.1. Unable to relay for (name).
        // see notes under Techdocs
        //client.Host = "localhost";  // setup the server / host sending the mail
        // client.UseDefaultCredentials = true;

    }

and in my button send we have the following

protected void btnSend_Click(object sender, EventArgs e)
    {
       Label1.Text =  SendEmail(txtFrom.Text, txtto.Text, txtcc.Text, Convert.ToInt32(txtport.Text), txtsubject.Text,txtbody.Text,txthost.Text);

    }

I have entered the Following in the Required Fields when i test the application

[B]To: [/B]Vuyiswa@its.co.za

[B]From:[/B]Vuyiswa@its.co.za

[B]CC:[/B]vuyiswamb@gmail.com
[B]
Subject:[/B] This is the Test for the mail in o!booking System

[B]Body[/B]If you Receive this e-mail Please confirm the receipt of this e-mail

[B]Port : [/B]25

[B]Host: [/B] mailserver.Vuyiswa.local

When i run my Application and clicking on the send button , i get the Following Error

System.InvalidOperationException: A recipient must be specified. at System.Net.Mail.SmtpClient.Send(MailMessage message) at _Default.SendEmail(String from, String to, String cc, Int32 port, String subject, String message, String Host) in c:\Vuyiswa\Email_test\Default.aspx.cs:line 51

Thanks

I forget to Add the To and when i Add the To i get a new Error

Thanks a lot for reminding me that part. i have added it and i get a new Error

System.Net.Mail.SmtpException: Syntax error, command unrecognized. The server response was: Microsoft Exchange Server 2003 POP3 server version 6.5.7638.1 (Mailserver.its.local) ready. at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) at _Default.SendEmail(String from, String to, String cc, Int32 port, String subject, String message, String Host) in c:\Vuyiswa\Email_test\Default.aspx.cs:line 53

Thanks

I think its a problem related to SSL. You can try with smtp.EnableSsl = True If does not resolve contact with mail server administrator.

It Did not work, but i Find the Code that works for gmail that looks like this

protected void Button1_Click(object sender, EventArgs e)
    {
        MailMessage mm = new MailMessage();

        SmtpClient smtp = new SmtpClient();

        mm.From = new MailAddress("Vuyiswa@its.co.za");

        mm.To.Add(new MailAddress("Dan@Gmail.com"));

        mm.To.Add(new MailAddress("Faj@CESC.co.za"));

        mm.Subject = "Hello";

        mm.Body = "<p>This is the E-mail Test for !Booking System</p>";

        mm.IsBodyHtml = true;

        smtp.Host = "smtp.gmail.com";

        smtp.EnableSsl = true;

        System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();

        NetworkCred.UserName = "vuyiswamb@gmail.com";

        NetworkCred.Password = "secret";

        smtp.UseDefaultCredentials = true;

        smtp.Credentials = NetworkCred;

        smtp.Port = 587;

        smtp.Send(mm);
    }
}

and it work ,but in my smtp it does not work, i need to talk to my Server Administrator

Thanks

This question has already been answered. Start a new discussion instead.