Saturday, September 29, 2012

SMTP Relay in Exchange 2007 OR Exchange 2010 (for testing )& Restricting Outbound Email



You may want to do some email testing in the staging environment for real customers minus sending them actually.
By Default exchange is not open realy.
If you already have exchange in your environment and it is  used in the production. then you need to create another dummy domain for the testing. e.g stage.local.
You can use a VM for installing both AD & Exchange on a single machine.
Open up the
exchange MMC
                Server Configuration
                                Hub Transport
 create a "new Receive connector"

 

  

 
 


Now Open the powershell
Get-ReceiveConnector "StageTest" | Add-ADPermission -User "NT AUTHORITY\ANONYMOUS LOGON" -ExtendedRights "ms-Exch-SMTP-Accept-Any-Recipient"

The above will allow the relay to the Anonymous group for that connector.

Now as we may not want that email will go outside the machine (to real customers). We need to create a "transport rule".
Create a user mailbox  e.g  "catchall" .  This will be catch all the emails that you will be sending to the real customer.

open exchange MMC
Organization Configuration==>Hub Transport ==> Transport Rules


Click on the new transport rule on the right side>
Give it a name e.g Mail Redirect


 
 

This should do the trick. To be extra sure you can remove the DNS and Gateway entry of the machine. (in that way this machine will  work inside the LAN only)


A Receive connector that is configured to accept messages from all remote IP addresses through SMTP port 25   This connector typically accepts connections from all IP address ranges. The usage type for this connector is Internal. This connector is created automatically during setup. This connector only accepts mail from other Exchange servers that are part of the same Exchange organization. By default, this connector does not accept anonymous submissions.


Monday, September 24, 2012

Message Tracking in Exchange 2007 & Exchange 2010 + powershell script

#add the below line for exchange 2007  & if you want to schedule the job with windows task scheduler. otherwise you can ignore it
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
# Control variables
$daystoparse=1
$smtpServer="192.168.x.x"
$from="user-send@myDomain.com"
$to="user-receive@myDomain.com"
$subject=" Failed mails report - " + (Get-Date -format F) + " PST"
$body=""

#Prepare target file name based on current date pattern, to second granularity
$date=Get-Date -format yyyy-MMM-dd-HH-mm-ss
$targetfile = "D:\Mailfail\MessageTrack" + $date + ".csv"

# Create start and end date for parsing the mail-log files
# Startdate is always relative to current date, 1 day back
# Enddate is now()
$today = get-date
$rundate = $($today.adddays(-$daystoparse)).toshortdatestring()
$startdate = $rundate + " " + $today.Hour + ":" + $today.Minute + ":" + $today.Second + " AM"
$enddate = Get-Date -format G

get-messagetrackinglog -ResultSize Unlimited -Sender:abc@myDomain.com -EventID "FAIL" -Start $startdate -End $enddate | select timestamp, eventid, source,messagesubject, sender, {$_.recipients},clientip, clienthostname, serverip, serverhostname, connectorid, {$_.recipientstatus}, totalbytes, recipientcount, relatedrecipientaddress, returnpath | export-csv $targetfile

$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = $from
$msg.To.Add($to)
$msg.Subject = $subject
$msg.Body = $body
$att = New-Object Net.Mail.Attachment($targetfile)
$msg.Attachments.Add($att)
$smtp.Send($msg)
$att.Dispose()
====================================

save the above script as by any name e.g messageTrack.ps1 and schedule it via windows job scheduler.

for that create a bat file e.g schedule.bat and put the below line.

Powershell.exe -command "& {d:\scripts\messageTrack.ps1}"





It is important to note that if you are running Exchange based scripts from the Windows Command prompt by passing them as a parameter to Powershell.exe you should add the following line at the top of each script:

For Exchange 2007

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

For Exchange 2010
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010



It will send one day report (mail fail) (or any other based on the argument you set) to the email id you choose.

If you want to send the email to multiple users then  add the users one by one and separate them by comma

$msg.to.add("user1@mydomain.com,user2@mydomain.com")

Ref:
     http://technet.microsoft.com/en-us/library/ee692801.aspx
     http://technet.microsoft.com/en-us/library/bb124926.aspx

- Exchange 2007 message tracking
- Message Tracking in exchange 2007
- How to track messages in exchange 2007
- Exchange 2007 message tracking attachment
-create message tracking in exchange 2007 and send them as attachment
-Exchange 2007 Script: how to run as a scheduled task


Saturday, September 15, 2012

Memory Leak

#ps -aux                         ==> check for the change in value of VSZ for zabbix agent


USER    PID %CPU %MEM    VSZ       RSS   TTY   STAT START   TIME COMMAND
root         1      0.0        0.0          24892  1576   ?        Ss        Jul01     0:06     /sbin/init
root         2      0.0         0.0         0              0     ?        S          Jul01     0:00    [kthreadd]
root         3      0.0         0.0         0              0     ?        S          Jul01     0:00    [migration/0]
root         4      0.0        0.0         0              0     ?        S          Jul01     0:29    [ksoftirqd/0]
root         5      0.0        0.0         0              0     ?        S          Jul01     0:00    [migration/0]
root         6      0.0        0.0        0               0    ?        S          Jul01     0:00    [watchdog/0]
zabbix   25064  0.0      0.0   50420    2272     ?        S      Aug27    25:03       /usr/sbin/zabbix_agentd
zabbix   25065  0.0      0.0   50436    1120   ?        S      Aug27     16:37         /usr/sbin/zabbix_agentd
zabbix   25066  0.0      0.0   50436    1120   ?        S     Aug27     16:42          /usr/sbin/zabbix_agentd
zabbix   25067  0.0     0.0   80436    1120   ?        S      Aug27     16:30          /usr/sbin/zabbix_agentd
zabbix   25068  0.0    0.0    70428     908   ?        S     Aug27       0:32             /usr/sbin/zabbix_agentd


Or you can also run the top command and press M.