How can I send multiple attachments in email using VB.NET

35 pts.
Tags:
VB.NET
Visual Basic
I am working on a code which is used to send email from the desktop application, it works fine. The main problem arises when i tried to attach multiple files or i tried to attach a heavy file (e.g. 1 Mb, or higher) Below is the code i have used. For i As Integer = 0 To Me.dgvMail.Rows.Count - 1 Dim SmtpServer As New SmtpClient() Dim mail As New MailMessage() SmtpServer.Credentials = New _ Net.NetworkCredential(EId, Pwd) SmtpServer.Port = PortNo SmtpServer.Host = Smtp mail = New MailMessage() mail.From = New MailAddress(EId) mail.To.Add(Trim(Me.dgvMail(0, i).Value)) mail.Subject = Trim(Me.txtMailHeader.Text) mail.Body = Trim(Me.txtEmail.Text) '' code to attach the attachment in the mail ''''''''''''''''' For Counter As Integer = 0 To lstAttachment.Items.Count - 1 Attachment = New System.Net.Mail.Attachment(lstAttachment.Items(Counter)) mail.Attachments.Add(Attachment) Next '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''' to get the mail sending fail notification mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure mail.Priority = MailPriority.High '************************************************************ SmtpServer.EnableSsl = True SmtpServer.Send(mail) Next

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following