コード例 #1
0
        public static void ProfessorSendMail(GradeDetailsModel gradeDetailsModel, StudentDetailsModel student)
        {
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress("Florin Olariu", "*****@*****.**"));
            message.To.Add(new MailboxAddress(student.Name, student.Email));
            message.Subject = "[" + gradeDetailsModel.ExamName + "]" + " Nota Examen";

            var attachment = new MimePart("image", "gif")
            {
                Content                 = new MimeContent(File.OpenRead($"..\\EMS.Presentation\\ClientApp\\src\\assets\\{gradeDetailsModel.ExamName}\\barem.png")),
                ContentDisposition      = new ContentDisposition(ContentDisposition.Attachment),
                ContentTransferEncoding = ContentEncoding.Base64,
                FileName                = Path.GetFileName($"..\\EMS.Presentation\\ClientApp\\src\\assets\\{gradeDetailsModel.ExamName}\\barem.png")
            };

            var body = new TextPart("plain")
            {
                Text = "Buna ziua, " + student.Name +
                       @"
                        Va anunt ca lucrarea dumneavoastra la materia " + gradeDetailsModel.ExamName +
                       " a fost corectata si nota este " + gradeDetailsModel.Value +
                       @".
                        Intrati in aplicatie si alegeti daca sunteti de acord cu aceasta nota sau nu. 
                        Mai jos am atasat baremul." +
                       "-O zi buna!"
            };


            var multipart = new Multipart("mixed");

            multipart.Add(body);
            multipart.Add(attachment);

            message.Body = multipart;

            using (var client = new SmtpClient())
            {
                // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;

                client.Connect("smtp.gmail.com", 465, true);

                // Note: only needed if the SMTP server requires authentication
                client.Authenticate("*****@*****.**", "mypassword.notsarcastic");

                client.Send(message);
                client.Disconnect(true);
            }
        }
コード例 #2
0
        public static void ProfessorSendMailUpdate(GradeDetailsModel gradeDetailsModel, StudentDetailsModel student)
        {
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress("Florin Olariu", "*****@*****.**"));
            message.To.Add(new MailboxAddress(student.Name, student.Email));
            message.Subject = "[" + gradeDetailsModel.ExamName + "]" + " Nota Examen";

            var body = new TextPart("plain")
            {
                Text = "Buna ziua, " + student.Name +
                       @"
                        Va anunt ca lucrarea dumneavoastra la materia " + gradeDetailsModel.ExamName +
                       " a fost recorectata si nota este " + gradeDetailsModel.Value +
                       "-O zi buna!"
            };


            var multipart = new Multipart("mixed");

            multipart.Add(body);

            message.Body = multipart;

            using (var client = new SmtpClient())
            {
                // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;

                client.Connect("smtp.gmail.com", 465, true);

                // Note: only needed if the SMTP server requires authentication
                client.Authenticate("*****@*****.**", "mypassword.notsarcastic");

                client.Send(message);
                client.Disconnect(true);
            }
        }