Sending Email from asp.net Application [Resolved]

Posted by .Netlearner under ASP.NET on 3/19/2013 | Points: 10 | Views : 2454 | Status : [Member] | Replies : 16
Hello All,

I want to send email when my users got registered in my site.

Am using visualstudio 2010 and IIS7

I refered many links in DOTNETFUNDA too, but there was no error yet the mail is not sent. MailRoot folger is empty.no other error message in code.

My Code
 SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
MailMessage mail = new MailMessage();
mail.From = new MailAddress("diamondloga@gmail.com");
mail.To.Add("mynameiskutima@gmail.com");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";

SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential("ecommerce", "ecommerce");
SmtpServer.EnableSsl = true;

SmtpServer.Send(mail);


In web.config:

  <system.net>
<mailSettings>
<smtp >
<network host="localhost" port="25" />
</smtp>
</mailSettings>
</system.net>


am using IIS7 and i have installed smtp server and have assigned its properties too.Please guide me whether am wrong ? or how to send mail?




Responses

Posted by: Ankitsrist on: 3/19/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
put this code after body section bcoz u have wrote wrong port no.
SmtpClient smtp=new SmtpClient();


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

smtp.Port=587;

smtp.Credentials =new System.Net .NetworkCredential("uremailid@gmail.com", "ur password");

smtp.EnableSsl =true ;

smtp.Send(msg);




.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/19/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

refer this url

http://www.dotnetfunda.com/codes/code4265-how-to-registered-losgin-users-and-send-email-at-the-time.aspx

Mark as Answer if its helpful to you

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 3/19/2013 [Member] Starter | Points: 25

Up
0
Down
What should i specify in place of hostname. [Localhost] ? am i right or what should i specify there should i mention anything in web.config file.Whether this executes in IIS7 ?

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 3/19/2013 [Member] Starter | Points: 25

Up
0
Down
hello
you dont need to do changes in web.config file...refer my coding in this same website
http://www.dotnetfunda.com/codes/code3930-sending-email-through-aspnet-applicationcontactfeedback-form-eg.aspx

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/19/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

put smtp server name

Mark as Answer if its helpful to you

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 3/19/2013 [Member] Starter | Points: 25

Up
0
Down
MailMessage mm = new MailMessage();

SmtpClient smtp = new SmtpClient();

mm.From = new MailAddress("diamondloga@gmail.com");

mm.To.Add(new MailAddress(txtemail.text));

// mm.To.Add(new MailAddress("moreemail@vuyiswa.co.za"));

mm.Subject = "Registered Successfully";

mm.Body = "Registered";
System.Net.NetworkCredential credential = new System.Net.NetworkCredential("diamondloga@gmail.com", "logamaymay"); 

SmtpClient smtp = new SmtpClient();
smtp.UseDefaultCredentials = true;
smtp.Credentials = credential;
smtp.Host = "smtp.gmail.com";
smtp.UseDefaultCredentials = true;

smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Send("mm");


i have changed as mentioned in your code and still am not able to send mail. Please point out my mistake.

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Somu475 on: 3/19/2013 [Member] Starter | Points: 25

Up
0
Down
Change like this...

smtp.Host = "10.2.0.21"; 

smtp.Port = 25;


To find the Host name of your system refer following link.

http://live-free.hubpages.com/hub/How-to-Find-the-SMTP-Host-Name-and-Address-of-your-ISP

-Somu

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 3/19/2013 [Member] Starter | Points: 25

Up
0
Down
i cant find my host name in command prompt. Am not familiar with that too. is that the cause for not delivering the email

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mutturaj on: 3/19/2013 [Member] Starter | Points: 25

Up
0
Down
Try like this...
As you have mentioned your gmail account credentials, set smtp.UseDefaultCredentials = False;

MailMessage mm = new MailMessage(); 

mm.From = new MailAddress("diamondloga@gmail.com");
mm.To.Add(new MailAddress("moreemail@vuyiswa.co.za"));
mm.Subject = "Registered Successfully";
mm.Body = "Registered";

SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = False;
smtp.Credentials = new System.Net.NetworkCredential
("diamondloga@gmail.com", "logamaymay");
smtp.EnableSsl = true;
smtp.Send(mm);


.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 3/19/2013 [Member] Starter | Points: 25

Up
0
Down
remove one smtp.UseDefaultCredentials = true; from ur code u have put this twice, and even u dont need to write this

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 3/20/2013 [Member] Starter | Points: 25

Up
0
Down
Its working now. I changed SMTP settings in IIS7. SMTP server name was mentioned as localhost and i changed that to gmail.Its working now thanks for all your comments

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 3/20/2013 [Member] Starter | Points: 25

Up
0
Down
thanks :)
njoy coding

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 3/20/2013 [Member] Starter | Points: 25

Up
0
Down
How to use plain smtp what i mean is how to send mail without using gmail as smtp server i want any id to send data. SMTP server name is localhost . how to acheive this


.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 3/20/2013 [Member] Starter | Points: 25

Up
0
Down
no you cannot send mail without using smtp host

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 3/20/2013 [Member] Starter | Points: 25

Up
0
Down
no not without smtp host, in my smtp instead of using smtp.gmail.com i want to send from my local host ip im my smtp.

SmtpClient smtp = new SmtpClient("127.0.0.1");// this IP denotes localhost


smtp.UseDefaultCredentials = false;

smtp.Credentials = new System.Net.NetworkCredential ("cartoro@mydomain.com", "*****123");

smtp.Send(mm);


.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 3/20/2013 [Member] Starter | Points: 25

Up
0
Down
I want to send mail from any email id (noy oly gmail) in that case how its possible.can anyone please guide me

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response