I have multiple PDF documents that will be dropped into a directory daily. I have a program right now that will extract information from the PDF and can place that information in the filename. One of those things is the fax number. I have file named "9015446622 [Name Name Name] Name (Date).pdf". I also have a powershell script, (can be VBS if you can easily find one or have one available) that will an authenticated email with an attachement to an outside email address. We would like to utilize an eFax email address to send the faxes through email. So basically the document above will be sent to 9015446622@efaxsend.com with the attached pdf. Since I have multiple PDFs in this folder I would need to be able to run this script for every filename and get the first 10 characters which is the fax number and add to the email address section. It should be a simple looping statement with a variable, I just don't know where to start on that part.
Here is a powershell code I have to send the email with the attachment.
A VBS script would work too.
Thanks everyone for your time!
Here is a powershell code I have to send the email with the attachment.
Code:
#EMail Example
$smtp = new-object Net.Mail.SmtpClient("mailrelay.yourdomain1.com") #Dns name or IP
#Auth Stuff
$smtpuser = new-object System.Net.networkCredential
$smtpuser.domain = "mydomain" #Only needed if you have a domain
$smtpuser.username = "myusername"
$smtpuser.password = "mypassword"
$smtp.Credentials = $smtpuser
##Need something there to input the first 10 characters from the file name and append @sendefaxnow.com##
$smtp.Send("myaccount@email.edu", "someone@gmail.com", "PowerShell Email", "This is a email from powershell")
function do_mail ($myhtml) {
##Need something here to attach the current PDF in the path below.##
$attachmentpathandfilename = "C:\windows\WindowsUpdate.log"
$mymail = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient("mailrelay.yourdomain1.com") #Dns name or IP
$mymail.IsBodyHTML = $true
$mymail.From = "ServerReporting@Company.edu"
$mymail.To.Add("sysadmins@company.edu")
$mymail.Subject = ("My Html email example")
$mymail.Body = $myhtml
$mymail.Attachments.Add($attachmentpathandfilename)
$smtp.Send($mymail)
} #do_mail
$head = "<style>"
$head = $head + "BODY{background-color:#9FAEB5;}"
$head = $head + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$head = $head + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#999999}"
$head = $head + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#CCCCCC}"
$head = $head + "</style>"
$myhtml = Get-childitem | select name, FullName, length | ConvertTo-HTML -head $head -body ("<H2>My Example Html email</H2>")
do_mail $myhtml
A VBS script would work too.
Thanks everyone for your time!