I have a doubt
if a user is registered at the website that particular user information i.e user name and password is sent automatically to the user's email...how this process gets done????one more thing i have created a .cs file named registration.cs for inserting user records into database now the thing is where should i write the email script to send that information to the user should i need to continue in the same registration.cs file or should i need to create a separate .cs file to write the email code to get the things done

Nilanka DharmadasaRank #1,875 · 794 reputationPosted Dec 16, 2009, 12:20 AM EST
You have to programmetically send an email once the user registration is done. There are plenty of c# examples on the web to send emails.
If you want you can write the sending email part in the same .cs file. But it's nice to write it in a separate .cs file.
If you have any other problem please ask.
If you find my answer useful, please check 'Do you like my answer' checkbox.
kiran kumarRank #3,110 · 461 reputationPosted Dec 16, 2009, 12:33 AM EST
Lalit MRank #1,186 · 1.5K reputationPosted Dec 16, 2009, 12:41 AM EST
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Mail;
public static void sendEmail()
{
string fromEmail = "";//sending email from...
string ToEmail = "";//destination email
string body = "";
string subject = "";
try
{
SmtpClient sMail = new SmtpClient("");//exchange or smtp server goes here.
sMail.DeliveryMethod = SmtpDeliveryMethod.Network;
//sMail.Credentials = new NetworkCredential("username","password");this line most likely wont be needed if you are already an authenticated user.
sMail.Send(fromEmail,ToEmail, subject, body);
}
catch(Exception ex)
{
//do something after error if there is one
}
}
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Dec 16, 2009, 12:44 AM EST
Add the code in red color to your code.
SqlParameter uid= new SqlParameter("@userid",SqlDbType.NVarChar,50);
uid.Value = newuserid.ToString();
cmd.Parameters.Add(uid);
Check and let me know the result.
kiran kumarRank #3,110 · 461 reputationPosted Dec 16, 2009, 12:56 AM EST
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Dec 16, 2009, 1:39 AM EST
E mail sending part can be done as follows.
First add a class file (.cs file) named 'EmailSender' to your project.
Then write the code as follows.
using System; using System.Collections.Generic; using System.Text; namespace WindowsFormsApplication2 { public class EmailSender { System.Net.Mail.SmtpClient smtpConnection; public EmailSender() { smtpConnection = new System.Net.Mail.SmtpClient(); smtpConnection.Host = "mail.usermail.net";//Your mail server's ip or name. smtpConnection.Port = 25;//The port smtpConnection.Credentials = new System.Net.NetworkCredential("username", "password");//Username and password to access mail server } public void SendMail(string Username, string password, string email) { string mailbody = String.Format("This is your account details. Username: {0}, Password: {1}", Username, password); System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); message.To.Add(email); message.Subject = "Your account details"; message.From = new System.Net.Mail.MailAddress("[email protected]");//Give your from e mail address here message.Body = mailbody; smtpConnection.Send(message); } } }Then call the 'SendMail' method in your previous class after inserting data to the databse.
........
........
cmd.ExecuteNonQuery();
con.Close();
EmailSender obj = new EmailSender();
obj.SendMail(CreateUserWizard1.UserName, CreateUserWizard1.Password, CreateUserWizard1.Email);
kiran kumarRank #3,110 · 461 reputationPosted Dec 16, 2009, 2:38 AM EST
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Dec 16, 2009, 3:05 AM EST
This example uses simple mail transfer protocol.
Mail me with your exact requirement. (I mean what's the mail server that you use.)
kiran kumarRank #3,110 · 461 reputationPosted Dec 16, 2009, 3:10 AM EST
mihir soni41 reputationPosted Dec 21, 2009, 9:32 PM EST
and if your website hosting provide smtp server than you can use their email server.