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 DharmadasaPosted Dec 16, 2009, 5:20 AM
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.
mihir soniPosted Dec 22, 2009, 2:32 AM
and if your website hosting provide smtp server than you can use their email server.
kiran kumarPosted Dec 16, 2009, 8:10 AM
Nilanka DharmadasaPosted Dec 16, 2009, 8:05 AM
This example uses simple mail transfer protocol.
Mail me with your exact requirement. (I mean what's the mail server that you use.)
kiran kumarPosted Dec 16, 2009, 7:38 AM
Nilanka DharmadasaPosted Dec 16, 2009, 6:39 AM
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.
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 kumarPosted Dec 16, 2009, 5:56 AM
Nilanka DharmadasaPosted Dec 16, 2009, 5:44 AM
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.
Lalit MPosted Dec 16, 2009, 5:41 AM
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
}
}
kiran kumarPosted Dec 16, 2009, 5:33 AM