Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is test page to send mail from my domain account to gmail account

C#
public partial class TestEmail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSendEmail_Click(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage();

        NetworkCredential cred = new NetworkCredential("example@hotel.allmyanmarbooking.com", "mydomainpassword"); //client's gmail and password

        mail.To.Add("ToUserAccount@gmail.com");
        mail.Subject = "Test Email"; //message subject

        mail.From = new MailAddress("example@hotel.allmyanmarbooking.com", "example@hotel.allmyanmarbooking.com");
        

        mail.IsBodyHtml = true;
        mail.Body = "trying to send to from domain email account"; //message body

        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.allmyanmarbooking.com";
        smtp.Port = 26;
        smtp.UseDefaultCredentials = false;
        smtp.EnableSsl = false;
        smtp.Credentials = cred;
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

            smtp.Send(mail);       

        lblEmail.Text = "Send Successful..";
    }
}


when i clicked the send button, i saw that error

No connection could be made because the target machine actively refused it 66.197.198.196:26
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 66.197.198.196:26

Source Error:

Line 37:         smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
Line 38: 
Line 39:             smtp.Send(mail);       
Line 40: 
Line 41:         lblEmail.Text = "Send Successful..";


i don't know how to solve..
my domain smtp support port 25 & 26
i tried both of them.. but i couldn't solve it..

:)
Posted
Updated 20-Feb-12 22:36pm

If this happens always, it literally means that the machine exists but that it has no services listening on the specified port, or there is a firewall stopping you.

If it happens occasionally - you used the word "sometimes" - and retrying succeeds, it is likely because the server has a full backlog.

You can try the below code
C#
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(gMailAccount, password);


If the problem continues, then it would be GMail server issue.
 
Share this answer
 
Comments
Doyle Raymond 21-Feb-12 5:13am    
no, what i mean is
my smtp server is not gmail...

but from other service..

i'm wondering the name of smtp.Host depends on my smpt name ???

or should i change something... ??

the flow is..
when a customer is clicked a request,
that mail will be received to my domain account and then
transfer to respective hotel gmail or email account..

my domain account is not gmail account..

thanks a lot
AmitGajjar 21-Feb-12 5:18am    
is this your mail server IP ? -> '66.197.198.196'
Doyle Raymond 21-Feb-12 5:56am    
i don't know
in server information, they don't display server ip address
:(
Hi,

if you are sending through gmail account then use SSL enabled connection.

Here is the link for the gmail setting information.

this problem is normally setting problem only.

hope this will resolve your issue.

Thanks
-Amit.
 
Share this answer
 
Comments
Doyle Raymond 21-Feb-12 5:15am    
no, what i mean is
my smtp server is not gmail...

but from other service..

i'm wondering the name of smtp.Host depends on my smpt name ???

or should i change something... ??

the flow is..
when a customer is clicked a request,
that mail will be received to my domain account and then
transfer to respective hotel gmail or email account..

my domain account is not gmail account..

thanks a lot
AmitGajjar 21-Feb-12 5:20am    
if you have other smtp server then you need to get smtp server information from your hosting provider company. smtp host name may change from server to server.

thanks
-amit.
'target machine actively refused it' means that there is no service listing at that port. There can be multiple reasons for it.
The smtp server can not be running.
More likely there is a firewall in between that does not allow communication from you're system to 66.197.198.196 using port 26.

Another problem could be that the traffic is routed wrongly.

Piet
 
Share this answer
 
I have just tried to connect to this server and neither port 25, 26 nor 465 are accepting incoming connections. you need to contact the administrators of the site to find out which is the correct port for their SMTP service.
 
Share this answer
 
Comments
Mohammad A Rahman 21-Feb-12 6:22am    
Exact point :)
As Solution 4 mentioned, you can always check whether the server accepting any connection on port 25 with following command
SQL
C:\>telnet example@hotel.allmyanmarbooking.com 25

But in this case Telnet command raise following error message,
Connecting To example@hotel.allmyanmarbooking.com...Could not open connection to the host, on port 25: Connect failed

So the server is not configured to accept any incoming connections for SMTP.

:)
 
Share this answer
 
Comments
Doyle Raymond 21-Feb-12 23:10pm    
thanks a lot!!
is there any ways i can send to gmail via my domain??
how to close opened telnet and how about port 26 ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900