How to send mail to multiple recipients in Perl? - perl

I have to send mail to multiple recipients using Perl. I have to use Net::SMTP only to send mail.
I have to read from and to mail address from pipe separated file. Format of file is as follows:
abc#gmail.com|pqr#yahoo.com,xyz#gmail.com
I have read the line and split it wrt to pipe. Then I stored to part in $mailT
I tried using
smtp->recipient($mailT)
and
smtp->datasend("To: $mailT ");
but this is not working.
It gives the error:
Issue RCTP to in the command

Net::SMTP:
recipient ( ADDRESS [, ADDRESS, [...]] [, OPTIONS ] )
Notify the server that the current message should be sent to all of the addresses given. Each address is sent as a separate command to the server. Should the sending of any address result in a failure then the process is aborted and a false value is returned. It is up to the user to call reset if they so desire.
I couldn't identify how your code set $mailT but
the argument of recipient must be in an array or a list.
That could be an issue if that's a comma separated scalar.

Related

How to save all ip addresses connected to the network in a text file

I would like to create an alert software for employees without outsourcing for security reasons. I found a way to send alerts from cmd with msg command, I didn't test this code but I generated it from Microsoft site, if there is any error please let me know
msg #allip.txt "test"
For IP list, I found a solution using arp -a using cmd but I have to clear the extra info in the file like this, the problem is that if I leave the extra info in the text the code doesn't work
Interface: 192.168.1.140 --- 0x3
Internet Address Physical Address Type
192.168.1.1 00-00-00-00-00-00 dynamic
192.168.1.61 00-00-00-00-00-00 dynamic
192.168.1.255 00-00-00-00-00-00 static
...
Is there a way to save only the internet address table
To extract all the cached IP addresses - which is what arp.exe /a reports - use the following:
Note: Judging by the linked docs, these cached addresses, stored along with their "their resolved Ethernet or Token Ring physical addresses", with a separate table maintained for each network adapter, are the IP addresses the computer at hand has actively talked to in the current OS session, which is not the same as the complete set of computers connected to the network.
To scan an entire subnet for reachable IP addresses, consider a third-party function such as Ping-Subnet.
((arp /a) -match '^\s+\d').ForEach({ (-split $_)[0] })
To save to a file, say ips.txt, append > ips.txt or | Set-Content ips.txt.
Note:
In Windows PowerShell, you'll get different character encodings by these file-saving methods (UTF-16 LE ("Unicode") for > / ANSI for Set-Content)
In PowerShell (Core) 7+, you'll get BOM-less UTF-8 files by (consistent) default.
Use Set-Content's -Encoding parameter to control the encoding explicitly.
Explanation:
-match '^\s+\d' filters the array of lines output by arp /a to include only those starting with (^) at least one (+) whitespace char. (\), followed by a decimal digit (\d) - this limits the output lines to the lines showing cache-table entries.
.ForEach() executes a script block ({ ... }) for each matching line.
The unary form of -split, the string splitting operator, splits each matching line into an array of fields by whitespace, and index [0] returns the first such field.

New-TransportRule for appending disclaimers

This is pretty straightforward. I tried creating a rule in the EAC for sent messages, but it's not working as intended. Basically I need to create a rule that checks if any recipients (To, CC or BCC) are from outside my org. If there are any, append a disclaimer to EVERYONE in the recipients (including inside the org).
Doing this via the EAC doesn't work in the sense that when I specify the rule "If the message... is sent to 'Outside the organization' " it finds ONLY recipients outside the org and appends the disclaimer to them. However, I also need to append it for users inside the org if this condition verifies. Unfortunately doing it like this only recipients from outside the org are receiving the appended disclaimer, but not company workers.
I've been working with PS quite a lot lately and New-TransportRule seems to be the way to go to do this, but reading through the documentation hasn't helped me a lot on how to structure said query to do exactly what I want or even how to only apply it to one person for testing purposes.
Any of you guys worked with this cmdlet before and could give me a quick hand?
Thanks!
It's been some time since I've managed Exchange, but judging from the documentation, I'd say you could probably take advantage of the AnyOfRecipientAddressMatchesPatterns predicate (emphasis added):
-AnyOfRecipientAddressMatchesPatterns
[...]
The AnyOfRecipientAddressMatchesPatterns parameter specifies a
condition that looks for text patterns in recipient email addresses by
using regular expressions. You can specify multiple text patterns by
using the following syntax: "Regular expression1","Regular
expression2",..."Regular expressionN".
A match for this condition applies the rule action to all recipients
of the message. For example, if the action is to reject the message,
the message is rejected for all recipients of the message, not just
for the specified recipients.
So let's start by constructing an appropriate pattern:
# Define internal recipient domains
$internalDomains = 'ress.tld','internal.ress.tld','ress-alias.tld'
# Escape as literal regex pattern
$internalDomains = $internalDomains |ForEach-Object { [regex]::Escape($_) }
# Embed in negative look-behind pattern
$nonInternalDomainPattern = "(?<!#(?:$($internalDomains -join '|')))"
The resulting regex pattern will match any email not having any of the three domains listed:
PS ~> $nonInternalDomainPattern
(?<!#(?:ress\.tld|internal\.ress\.tld|ress-alias\.tld))$
PS ~> 'ress#ress.tld' -match $nonInternalDomainPattern # doesn't match on internal recipients
False
PS ~> 'iisresetme#example.org' -match $nonInternalDomainPattern # but it matches any other address
True
Now you just need to include it in a transport rule:
New-TransportRule "Disclaimer on all external communications" -AnyOfRecipientAddressMatchesPatterns $nonInternalDomainPattern -ApplyHtmlDisclaimerText '<your>html goes here</your>'

Wrong Email Error message - By Sendmail unix

Does sendmail command returns any errors if we use wrong email id with correct e-mail id pattern?
If it is not how to identify if e-mail is delievered?
Yes Nitin, unix does give an output if the email remains undelivered. you can check in /var/spool/mail/home_dir
For example
mailx correct_addr#domain.com -s "Success Tested" correct_addr#domain.com < /tmp/dileep/test.txt
correct_addr#server:
you will see the prompt back to you, else look below
mailx correct_addr#domain.com -s "Success Tested" wrong_addr#domain.com < /tmp/dileep/test.txt
You have mail in /var/spool/mail/home_dir
correct_addr#server:
you can go and check the error message, if you would like to check or automate, you can monitor the home_dir for any mail delivery failures and send one email to you will all the details attached to the email and find out the wrong addresses.
NOTE: This works the same way for To and From addresses as well.

SSIS - Use data from Flat File Source in Subject Line of Send Mail task

We import files from an FTP. The file could be named anything.csv.
Every 15 mins, we use a Script Task to pull the directory listing of an FTP folder; then in a ForEach Loop Container (using Variable Enumerator) we download each FTP file, process it, delete it from the FTP and send a generic "Complete" email to confirm a file has been processed.
Is there a way we can use one of the columns ([ClientName]) in the anything.csv data file and put in the Subject line of the email we send out. So it reads "[ClientName] order has been imported"
I've tried using an Object variable (via a Recordset Destination and it's VariableName), but I get the error "the datatype of variable "User::Subject" is not supported in an expression".
Thanks
Chris
If you only want one client name per .csv file, you need to populate a string-type variable with just one clientname from the file. Then you will be able to use that string variable to build the subject line expression.

how to send mail(smtp) in telnet with special character "."

This mail will be sent with a line of "." However,if i want to set a line of "." in my body mail, how can i do?
telnet 192.168.1.1 25
HELO felix
MAIL FROM: <user#host.examplex.com>
RCPT TO: <user#host.examplex.com>
DATA
From: "support" <support#felix.cn>
To: <jqye#felix.cn>
Subject: Test mail
Test mail
Body of email
End
.
QUIT
The easy way is 'Dot followed by space'.
Every time a line starts with a dot, you should actually send two dots.
eg.:
..
Should give you the desired result: A single dot.
The server would then remove the first dot.
This is also known as 'dot-stuffing' (try looking it up).
See also SMTP dot stuffing - who does it and who removes it