Gmail Email Attachment Strnage behavior with VB Application

~OSD~ 2,131 Reputation points
2020-12-17T13:30:50.547+00:00

Hi,

I would like to send ALL (files and folders to email attachment with VB). But seems like all files are not attached but only two.
Here is the folder containing files to be attached.
49204-image.png

But I am getting only two files in attachment as:
49221-image.png
Ref to similar thread: https://video2.skills-academy.com/en-us/answers/questions/200638/files-folder-attachment-with-vbnet.html

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,644 questions
0 comments No comments
{count} votes

Accepted answer
  1. Karen Payne MVP 35,366 Reputation points
    2020-12-17T20:18:58.06+00:00

    Hello @~OSD~

    Have you tried using MailKit, the replacement for Smtp classes.

    Microsoft recommends MailKit
    https://video2.skills-academy.com/en-us/dotnet/api/system.net.mail.smtpclient?view=net-5.0
    49304-a1.png

    Example

    You will need to configure setting.
    Imports System.IO
    Imports MailKit
    Imports MailKit.Security
    Imports MimeKit
    Imports MimeKit.Utils

    Public Class Operations  
        Public Shared Async Sub Example1()  
            Dim message = New MimeMessage()  
      
            message.From.Add(New MailboxAddress("Joey", "joey@friends.com"))  
            message.To.Add(New MailboxAddress("Alice", "alice@wonderland.com"))  
      
            message.Subject = "Hello friend"  
      
            Dim builder = New BodyBuilder()  
            Dim image = builder.LinkedResources.Add("C:\Users\Joey\Documents\Selfies\selfie.jpg")  
      
            image.ContentId = MimeUtils.GenerateMessageId()  
            Dim files = Directory.GetFiles("c:\").ToList()  
            For Each file As String In files  
                builder.Attachments.Add(file)  
            Next  
      
      
            builder.HtmlBody =  
                $"<p>Hey Alice,<br>  
    <p>What are you up to this weekend? Monica is throwing one of her parties on  
    Saturday and I was hoping you could make it.<br>  
    <p>Will you be my +1?<br>  
    <p>-- Joey<br>  
    <center><img src=""cid:{image.ContentId}""></center>"  
            builder.Attachments.Add("C:\Users\Joey\Documents\party.ics")  
      
            message.Body = builder.ToMessageBody()  
      
            Using smtp = New Net.Smtp.SmtpClient()  
      
                AddHandler smtp.MessageSent, AddressOf MessageSent  
      
                Await smtp.ConnectAsync("smtp.gmail.com", 587, SecureSocketOptions.SslOnConnect)  
      
                Await smtp.AuthenticateAsync("Username", "Password")  
                Await smtp.SendAsync(message)  
                Await smtp.DisconnectAsync(True)  
      
            End Using  
      
        End Sub  
      
        Private Shared Sub MessageSent(sender As Object, e As MessageSentEventArgs)  
            Console.WriteLine(e.Response)  
        End Sub  
    End Class  
    
    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. ~OSD~ 2,131 Reputation points
    2020-12-18T23:25:19.433+00:00

    Thanks Karen. will check that out.

    1 person found this answer helpful.
    0 comments No comments