How to send query content as xml zip file to an email according to row

Maybe this using powershell? can also be done with ssis script c#

$Username = "MyUserName";
$Password = "MyPassword";

function Send-ToEmail([string]$email, [string]$attachmentpath){

    $message = new-object Net.Mail.MailMessage;
    $message.From = "Micheale@gmail.com";
    $message.To.Add($email);
    $message.Subject = "Monthly Report";
    $message.Body = "Greetings, Attached you will find";
    $attachment = New-Object Net.Mail.Attachment($attachmentpath);
    $message.Attachments.Add($attachment);

    $smtp = new-object Net.Mail.SmtpClient("localhost", "25");
    #$smtp.EnableSSL = $true;
    $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
    $smtp.send($message);
    write-host "Mail Sent" ; 
    $attachment.Dispose();
 }
 
$sql = "SELECT * from boomshaka"
$Rows = Invoke-Sqlcmd -ServerInstance localhost -Database grafana -Query $sql

ForEach( $Row in $Rows)
{
   	$file = "D:\reports\" + $Row.Email + ".xml"
    $Row.cpu | Out-File -FilePath $file
	$file
    Send-ToEmail  -email $Row.Email -attachmentpath $file;
}