INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Send Email to Email Address based on first 10 characters of file name

Send Email to Email Address based on first 10 characters of file name

Send Email to Email Address based on first 10 characters of file name

(OP)
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 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 the code I have to send the email with the attachment.

CODE --> powershell

#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, but I am trying to powershell it up.

Thanks everyone for your time!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close