Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The below mentined code doesnt gives any error but when checking the inbox there is no mails.i.e the mail is not sent,Please guide

C#
MailMessage Msg = new MailMessage();
        Msg.From = new MailAddress("sales@mydomain.com", "Testing");
        Msg.To.Add(TxtEmail.Text);
        Msg.Subject = "Send Mail with HTML File";
        Msg.Body = myString.ToString();
        SmtpClient client =new SmtpClient();
        client.Host="mail.mydomain.com"; 
        client.Port=25; 
        client.Credentials= new NetworkCredential("sales@mydomain.com","password");
        client.Send(Msg);
Posted
Updated 8-May-13 19:41pm
v3
Comments
Member 9176543 10-May-13 12:39pm    
My intension was not to waste any ones time, its true that the above mentioned code is not copy pasted properly I have typed it and as per your comment the missing method is already mentioned above, infact there is a compile time error here Msg.Body = myString.ToString();
Before posting my query I have searched the web for examples major examples belongs to sending email through gmail which is running properly but rare article on sending through newly hosted domain name.
Correct code is
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress("sales@mydomain.com", "Testing");
Msg.To.Add(TxtEmail.Text);
Msg.Subject = "Send Mail with HTML File";
Msg.Body = "Test";
SmtpClient client = new SmtpClient();
client.Host = "mail.mydomain.com";
client.Port = 25;
client.Credentials = new NetworkCredential("sales@mydomain.com", "password");
client.Send(Msg);

This is not nice: you send us not the code you are using, but something else. For example, this line would not compile:
C#
SmtpClient client = new SmtpClient; // should be: new SmtpClient();


This is not that helping you is impossible. The problem is different: if we help, we should assume that you could be trusted. Nobody wants to waste time. Who knows what else in your code is different from the text you show in your post? And if we don't know, why wasting time on looking at your code?

There is another reason for not taking your question seriously. If you real code compiles (as you reported), it means it does exist. You did not bother copy and paste it properly. Have you been uncomfortable with that? If you get help, how can we be sure that you are able to use it?

I would not spend so much time on writing all that if I did not want to help. Of course, I am trying to help, but I want to play fairly. Let's respect each other's time and effort.

As to the problem: 1) there a a lot of code samples around; so you can always find the simplest code sample on the Web and compare your code with them; 2) how can you be sure that your SMPT server is installed properly and authentication is correct? you can check it up using any available working mail client program.

This should be quite enough for you to fix the problem. Please try.

—SA
 
Share this answer
 
v2
Comments
Member 11548795 6-Apr-18 3:48am    
Hello,
How can i do that with my own host domain...
I write it but its gives error. failure sending mail & sometimes server require secure connection.
How i can resolve it by using my own host domain
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress("sales@mydomain.com", "Testing");
Msg.To.Add(TxtEmail.Text);
Msg.Subject = "Send Mail with HTML File";
Msg.Body = "Test";
SmtpClient client = new SmtpClient();
client.Host = "mail.mydomain.com";
client.Port = 25;
client.Credentials = new NetworkCredential("sales@mydomain.com", "password");
client.Send(Msg);
The above mentioned code works only for .com domains.
 
Share this answer
 
Comments
Member 11548795 6-Apr-18 3:48am    
Hello,
How can i do that with my own host domain...
I write it but its gives error. failure sending mail & sometimes server require secure connection.
How i can resolve it by using my own host domain
Have you conform that port 25 is open?
Smtp is white listed.
You can configure Smtp like bellow.
C#
SmtpClient client= new SmtpClient(); 
client.Host = "smtp.live.com"; 
client.Credentials = new NetworkCredential( 
    "myaccount@live.com", "mypassword"); 
client.EnableSsl = true;


But you code look fine.
 
Share this answer
 
v2
Comments
Richard C Bishop 10-May-13 14:23pm    
Please do not ask questions or leave comments as solutions to questions. See a problem with that logic?
Member 9176543 12-May-13 0:47am    
How do I confirm these two things
Have you conform that port 25 is open?
Smtp is white listed.
Member 11548795 6-Apr-18 3:48am    
Hello,
How can i do that with my own host domain...
I write it but its gives error. failure sending mail & sometimes server require secure connection.
How i can resolve it by using my own host domain

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