Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
This is pankaj here
Here is my code for running email application.But its not working what is the problem in it.Please check my code and respond me for the same,Thanks in advance
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
 message.From = new MailAddress("education@jssindia.com");
            message.To.Add("singh7pankaj@gmail.com");
 message.Subject = "Welcome Surabhi Publishing House User!";
 message.Body = "hello";

            message.IsBodyHtml = true;
            message.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.OnFailure;
SmtpClient client = new SmtpClient();
            client.UseDefaultCredentials = true;
            client.Timeout = 100000;
 client.Send(message);

In web config file what i attach is here
<system.net>>
<mailsettings>
<smtp from="education@jssindia.com">
<network defaultcredentials="true" host="myhostname" password="mypassword" username="myusername" port="25">;
</network></smtp>
</mailsettings>
</system.net>
Posted
Updated 11-May-11 0:36am
v3
Comments
OriginalGriff 11-May-11 6:35am    
Do you get an error? Or what does happen?
singh7pankaj 11-May-11 6:51am    
yes I got error and error is failure sending mail
Mohammed Asif.K 11-May-11 7:03am    
Please follow Solution 5/6

Looks like you are using GMAIL for email.

Use:
host: smtp.gmail.com
port: 587

Make sure the config entry values are correct. (for now, it looks a copy-paste)

More details here:
Send Emails with Gmail Account with Attachment[^]
Sending Email with Gmail, Yahoo, AOL, and Live Mail Via SMTP[^]

UPDATE:
Use ASP.NET to send Email from Website[^]
Tutorials on sending Email in ASP.NET[^]
 
Share this answer
 
v3
Comments
singh7pankaj 11-May-11 6:47am    
I am not using gmail account.I used my own i.e mail.jssindia.com
.I also used gmail but it gives this error
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. f1sm5443152pbn.22
Sandeep Mewara 11-May-11 6:51am    
Provide SMTP server and proper credentials for what you are using.
singh7pankaj 11-May-11 6:52am    
In gmail settings?
Sandeep Mewara 11-May-11 6:53am    
No. In code.
Sandeep Mewara 11-May-11 6:55am    
I have updated my answer with more links to learn on email form asp.net

Go through it and try.
MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient();
message.From = new MailAddress("mail@examples");
message.To.Add(new MailAddress("asifkem@gmail.com"));
string msg = "Hi";

message.IsBodyHtml = true;
message.Subject = "New Appointment | Apple Medical Center";
message.Body = msg;
smtp.Host = "relay-hosting.secureserver.net";
smtp.Port = 25;
smtp.UseDefaultCredentials = false;
smtp.Send(message);
status = true;

//Import this namespace
using System.Net.Mail;
 
Share this answer
 
Comments
singh7pankaj 11-May-11 7:09am    
Its againg giving error failure sending mail.what i did,just copy your code and change the email address then also its given error
Mohammed Asif.K 12-May-11 1:28am    
heloo..doesn't work this code live?
Mohammed Asif.K 12-May-11 1:30am    
Please give your domain server name?
VB
string strTo = email;
string strFrom = "mail@applemedicalcenter";
string strSubject = "New Appointment";
string msg = "Hi, Admin\n" + "\n"
+ " " + "Mr/Mrs: " + name + " had sent a request for a new appointment.His details are mentioned below:\n"

SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(strFrom, strTo, strSubject, msg);
status = true;
 
Share this answer
 
v2
Comments
singh7pankaj 11-May-11 6:58am    
Its not working
Mohammed Asif.K 12-May-11 1:29am    
Where Live/Local?First please give Your Server Name.?
I am not using gmail account.I use my own own i.e mail.jssindia.com
 
Share this answer
 
Comments
Toniyo Jackson 11-May-11 6:39am    
Don't write your comments here. You can use the Add Comment button under Answer

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