Hi, all.
I'm new to C# programming. I'm even newer to programming email
capabilities into my code. What I need to do is create three (3)
functions:
* sendEmail, using a Mail object (which needs to be created) as a
parameter
* forgotPassword, using whatever arguments it needs -- uses sendEmail
to send lost password to user
* sendRegistratio nInfo, using whatever arguments it needs -- uses
sendEmail to send registration info to user
Can someone please take a look at this code and tell me if it makes
sense? Building the code doesn't throw any errors.
[(...) denotes code that has been eliminated because it is not
pertinent to the code at hand.]
=============== =============== ============
(...)
using System.Net;
using System.Net.Mail ;
using System.Net.Mime ;
(...)
(...)
public class Mail
{
SmtpClient client = new
SmtpClient(Syst em.Configuratio n.Configuration Manager.AppSett ings["Smtp"].ToString());
MailAddress From;
MailAddress To;
String Subject = "[Company Name] "; // rest of subject will be
appended as necessary in appropriate function(s)
String Body = "Hi,"; // rest of message will be appended as necessary
in appropriate function(s)
System.Net.Mail .MailMessage msg = new
System.Net.Mail .MailMessage(Fr om, To);
}
public class SendEmail
{
public static void sendEmail(Mail mail)
{
try
{
mail.client.Sen d(mail);
mail.msg.Dispos e();
}
catch (Exception e)
{
throw new Exception(e.Mes sage);
}
}
}
public static void forgotPassword( string Recipient, string Password)
{
try
{
Mail mail = new Mail();
mail.From = new MailAddress("do **********@site .com", "do-not-
re***@site.com");
mail.To = new MailAddress(Rec ipient);
mail.Subject += "Your Password";
mail.Body += Environment.New Line;
mail.Body += Environment.New Line + "You requested recovery of your
password. Here is your password:";
mail.Body += Environment.New Line + Password;
sendEmail(mail) ;
}
catch (Exception e)
{
throw e;
}
}
public static void sendRegistratio nInfo(string Recipient, string
ScreenName, string Password)
{
try
{
Mail mail = new Mail();
mail.From = new MailAddress("re ******@site.com ",
"re******@site. com");
mail.To = new MailAddress(Rec ipient);
mail.Subject += "User Registration";
mail.Body += Environment.New Line;
mail.Body += Environment.New Line + "Thank you for registering with
us! Here is your user information:";
mail.Body += Environment.New Line + "Screen Name: " + ScreenName;
mail.Body += Environment.New Line + "Password: " + Password;
sendEmail(mail) ;
}
catch (Exception e)
{
throw e;
}
}
}
=============== =============== ============
Again, I'm new to all of this. Also. My professors have always told me
that my logic is wonky. So when errors do pop up, I'm usually confused
because my logic flow makes sense to me. The compiler, however, seems
to think otherwise :P
I would really appreciate any criticism (constructive or otherwise).
Thanks,
Allie