Thursday, October 4, 2018

Send email with multiple attachment by using yahoo server in C# code


 try
                {
                    var message = new MailMessage(txtsenderEmail.Text, txtrecEmail.Text);
                    message.Subject = txtSubject.Text;
                    message.Body = rboxBody.Text;
                    if (txtattachement.TextLength > 0)
                        message.Attachments.Add(new Attachment(txtattachement.Text));
                    if (textattechment2.TextLength > 0)
                        message.Attachments.Add(new Attachment(textattechment2.Text));
                    if (txtattech3.TextLength > 0)
                        message.Attachments.Add(new Attachment(txtattech3.Text));
                    using (SmtpClient mailer = new SmtpClient("smtp.mail.yahoo.com", 587))
                    {
                        mailer.Credentials = new NetworkCredential(txtsenderEmail.Text, txtPassword.Text);
                        mailer.EnableSsl = true;
                        mailer.Send(message);

                    }
                    txtattachement.Text = null;
                    txtSubject.Text = null;
                    txtrecEmail.Text = null;
                    rboxBody.Text = null;
                    MessageBox.Show("Email succesfull sent", "Message");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error" + ex, "Message");
                }
            }

No comments:

Post a Comment