0

I am trying to send a confirmation mail after a user has registered on my website. I am using Webmatrix and ASP.NET to implement this.

I followed the code on this website http://www.asp.net/web-pages/tutorials/email-and-search/11-adding-email-to-your-web-site

For creating the SMTP server i used the IIS manager in Windows 7. But its not working.

I changed the settings to

WebMail.SmtpServer = "localhost";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = false;
WebMail.UserName = "name";
WebMail.From = "---@gmail.com";
WebMail.Password = "pass";

What do i put as my username and password for this? I am trying to test this on localhost. I dont have a server account.

Please help

Kris van der Mast
  • 16,343
  • 8
  • 39
  • 61
user1019083
  • 381
  • 2
  • 8
  • 19

2 Answers2

2

great tutorial how to do this is Sending email in .NET through Gmail

i have used it myself.

for sure i can see one error: WebMail.SmtpServer = "localhost"; <-- is the provider you are using to send email

localhost is the PC what are you using (unless you have your own smtp server)

the link will help as its only small change you need to do and you can after investigate

Community
  • 1
  • 1
cpoDesign
  • 8,953
  • 13
  • 62
  • 106
  • so i will set the smtpserver to "smtp.gmail.com", Port = 587, EnableSsl = true ? Username password will be my gmail login id? and from also will be gmail id? – user1019083 Mar 18 '12 at 20:48
  • @user1019083: yes you are correct, you need to provide your credentials for server to authorize you and from will be your details – cpoDesign Mar 18 '12 at 20:55
  • Thank you it works !! But right now it will show my email address in the from tag. What if I dont want to disclose it? is it possible – user1019083 Mar 18 '12 at 20:55
  • @user1019083: the data will be in code, so you do not disclose it. another way is set it up in web.config which is "better". If you do it for company you can create new account with data that will be shared – cpoDesign Mar 18 '12 at 20:57
  • I meant that when the user receives the mail, he will see my email address which is my personal account. I want it to be say it came from noreply@domain.com , so that the user does not reply back to that email id as well. For the time being localhost – user1019083 Mar 18 '12 at 20:59
  • @user1019083: not sure if you can change email from, you might aswell try this, and see whether you recieve the email as noreply@domain.com – cpoDesign Mar 19 '12 at 09:05
1

To send an e-mail you need an e-mail account. Your application will contact that server to send e-mails (if you're using GMail remember you need SSL so set it to true). That's why you can't use localhost as SMPT server: it's not an e-mail server!

Configuration can be done in the web.config file. See this article for more details about how to configure and use SmtpClient class.

Adriano Repetti
  • 65,416
  • 20
  • 137
  • 208