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
* sendRegistrationInfo, 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(System.Configuration.ConfigurationManag er.AppSettings["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(From, To);
}
public class SendEmail
{
public static void sendEmail(Mail mail)
{
try
{
mail.client.Send(mail);
mail.msg.Dispose();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
}
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(Recipient);
mail.Subject += "Your Password";
mail.Body += Environment.NewLine;
mail.Body += Environment.NewLine + "You requested recovery of your
password. Here is your password:";
mail.Body += Environment.NewLine + Password;
sendEmail(mail);
}
catch (Exception e)
{
throw e;
}
}
public static void sendRegistrationInfo(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(Recipient);
mail.Subject += "User Registration";
mail.Body += Environment.NewLine;
mail.Body += Environment.NewLine + "Thank you for registering with
us! Here is your user information:";
mail.Body += Environment.NewLine + "Screen Name: " + ScreenName;
mail.Body += Environment.NewLine + "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