简体   繁体   中英

Asp.net & C# email query?

I'm just wondering if someone could help me with a question, I would like if possible and not overly complicated to be able to click a button and when I do it will send an email to the person who submitted a change from the person logged in, this may sound confusing so is there anyway I can send an email to say a lecturer who wants something changed from the person who is logged in, I wouldn't want to manually type their email in each time because there could be many lecturers who send the changes for approval, I want to be able to send it to the person who in essence sent me the page for approval...

If anyone needs any further clarification to help me that would be great as im really struggling

Regards RD

try
    {
        MailMessage mail = new MailMessage();
        mail.From = new MailAddress("e_mail_from");
        mail.To.Add(new MailAddress("lecturer_email"));
        mail.Subject = "Plan approval";
        mail.Body = "I request my plan approval";
        SmtpClient client = new SmtpClient();
        client.Host = "smtp.gmail.com";
        client.Port = 587;
        client.EnableSsl = true;
        client.Credentials = new NetworkCredential("your_mail", "your_password");
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.Send(mail);
        mail.Dispose();
    }
    catch (Exception ex)
    {
        //...
    }
    finally
    {
        //...
    }

Instead of lecturer_email you have to appoint lecturer's email (may be from session, DB or something else, it's up to you). Your_mail it is your mail's name without domain (test@test.ru -> test). And your password as plain text. So it would be better if you will create some email for this function. I use with @gmail.com, it works excellent. Namespaces:

using System.Net;
using System.Net.Mail;

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM