Lab 6: Email (SMTP)

snottysurfsideServers

Dec 9, 2013 (3 years and 6 months ago)

85 views

Lab
6
:

Email (SMTP)

Objective:

To help students
to learn

how
email server work and write an email
announcement
.


[1] Installation:

1.

Insert
1
st

CentOS CD

into CDROM Drive, and boot the system with the CDROM.

2.

Type
linux text

from the
boot:

prompt.

3.

Select

sk
ip


from Media check

4.

Press
OK

5.

Select
English

and press
OK


6.

Select
us

and press
OK


7.

Select

Remove all partitions on selected drives and create default layout


and press
OK

8.

Press
Yes

9.

Press
Yes

10.

Press
OK

11.

Press
OK

(Boot Loader)

12.

Press
OK

13.

Set Boot Loader Passwor
d and press
OK

14.

Press
OK

15.

Select MBR and press
OK

16.

Press
Yes

on Network setup menu

17.

Select the following and press
OK

[*] Active on boot

[*] Enable IPv4 support

18.


Select DHCP


press
OK

19.

Hostname setup: select manually and enter the name of the host

20.

Set Time Zon
e: (Example: Los Angeles)

21.

Set Root Password

22.

Package Selection:


Unselect everything from the menu


Select the

Custom software Selection


and press
OK

23.

Package Group Selection:


Unselect everything from the menu press
OK

24.

Installation to begin: press
OK

25.

Af
ter installation, take out the CD and
reboot



[2]
Update system
:


[root@
server

/root]#
rpm
-

-
import /etc/pki/rpm
-
gpg/
RPM
-
GPG
-
KEY
-
*


[root@
server

/root]#
yum

y
update



Reboot

the system after update
complete
d.



[
3
]
Turn off the
unnecessary

services
:

[
root@
server

/root]#
chkconfig

list | grep 3:on |cut

c1
-
16 > off


Edit the file

off


and remove the daemon that you want to keep from the off list:

[root@
server

/root]#
vi off


Delete following list from off list:

network

iptables

syslog


crond

sendmail


sshd



[root@
server

/root]#
for
I

in $(cat off);do chkconfig $i off;service $i stop;done


[3]
Disable SELinux:

[root@
server

/root]#

echo 0 >> /selinux/enforce


[4] Firewall Rules
:

[root@
server

/root]#

vi /etc/sys
config/iptables


# Firewall configuration written by system
-
config
-
securitylevel

# Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

:RH
-
Firewall
-
1
-
INPUT
-

[0:0]

-
A INPUT
-
j RH
-
Fire
wall
-
1
-
INPUT

-
A FORWARD
-
j RH
-
Firewall
-
1
-
INPUT

-
A RH
-
Firewall
-
1
-
INPUT
-
i lo
-
j ACCEPT

-
A RH
-
Firewall
-
1
-
INPUT
-
p icmp
--
icmp
-
type any
-
j ACCEPT

-
A RH
-
Firewall
-
1
-
INPUT
-
p udp
--
dport 5353
-
d 224.0.0.251
-
j ACCEPT

-
A RH
-
Firewall
-
1
-
INPUT
-
m state
--
state ESTAB
LISHED,RELATED
-
j ACCEPT

-
A RH
-
Firewall
-
1
-
INPUT
-
m state
--
state NEW
-
m tcp
-
p tcp
--
dport 22
-
j ACCEPT

-
A RH
-
Firewall
-
1
-
INPUT
-
m state
--
state NEW
-
m tcp
-
p tcp
--
dport 25
-
j ACCEPT

-
A RH
-
Firewall
-
1
-
INPUT
-
j REJECT
--
reject
-
with icmp
-
host
-
prohibited

COMMI
T


[
5
]
Star
t

sendmail service:

[root@
server

/root]#
service sendmail restart



[
6
]
sendmail testing with telnet:


[root@
server

/root]#
telnet localhost 25

Trying 1
92
.1
6
8.
0
.
10x
...

Connected to
localhost

(1
92
.1
6
8.
0
.
10x
).

Escape character is '^]'.

220
loc
alhost

ESMTP Sendmail 8.13.1/8.13.1; Tue, 1 Nov 2011 16:54:40
-
0700


helo localhost


250
localhost

Hello
localhost

[1
92
.1
6
8.
0
.
10x
], pleased to meet you


mail from:
youremail
@gmail.com


250 2.1.0 youremail@gmail.com... Sender ok


rcpt to:
youremail
@
coyote.
c
susb.edu


250 2.1.5
youremail
@
coyote.
csusb.edu... Recipient ok


data


354 Enter mail, end with "." on a line by itself


Subject:
EMAIL TEST
.

This is an email test from localhost.

.


250 2.0.0 pA1Nsevn014654 Message accepted for delivery


quit


221 2.0.0
lo
calhost

closing connection

Connection closed by foreign host.


[7]
Write a script to sending email:



Create mailing list:

[ user@mail ~]$

cat list.txt

Ken Han
kenhan@gmail.com

John Smith
jsmith@yahoo.com

Steve Young syoung@49ers.com

Johnson Tayler jtaye
r@hotmail.com

William Woods bwoods@forest.com



David
McKinney

dmckinne@facebook.com



Bash script:

[ user@mail ~]$

vi
send


S
end:

#!/bin/bash


if [ $#
-
ne 1 ];then


echo "Usage: $0 fname
-
lname
-
email.txt";


exit;

fi


file=${1};

email="./
sendemail";


while read line

do


$email $line;

done < $file;

exit;



[ user@mail ~]$

vi sendemail


sendemail:

#!/usr/bin/perl

die "$0 emailaddress
\
n" if $#ARGV < 0;


my $fname = $ARGV[0];

my $lname = $ARGV[1];

my $to = $ARGV[2];


my $sendmail = '/us
r/lib/sendmail';

my $from = "ken
\
@csusb.edu";

my $subject = "[
CSE360
]: MESSAGE FROM
SCRIPT PROGRAMMING CLASS
";

my $header = `cat ./header`;

my $mesg = `cat ./m
e
sg`;

my $footer = `cat ./footer`;

print "Sending to: $to...
\
n";


open (MAIL, "|$sendmail
-
oi
-
t"
);

print MAIL "From: $from
\
n";

print MAIL "To: $to
\
n";

print MAIL "Subject: $subject
\
n";

print MAIL "MIME
-
Version: 1.0
\
r
\
n";

print MAIL "Content
-
Type: text/html; charset=ISO
-
8859
-
1
\
r
\
n";


print MAIL "$header
\
n";

print MAIL "Dear $fname $lname,<br><br>
\
n
\
n"
;

print MAIL "$header2
\
n";

print MAIL "$mesg
\
n";

print MAIL "$footer
\
n";

close(MAIL);


[ user@mail ~]$

vi header


header:

<html>

<head>

</head>

<body>


<font face=3D"Arial, sans
-
serif" size=3D"2">


<style type="text/css">

.style1 { font: 13px Arial; color:

rgb(52, 83, 133); }

.style2 { font: 11px Arial; color: rgb(102, 102, 102); }

.label { font
-
weight: bold; padding
-
right: 10px; }

.h1 { font
-
size: 120%; }

.h3 { font: italic bold 13px Arial; color: rgb(52, 83, 133); }

.h4 { font
-
size: 100%; font
-
weight: bol
d; }

.rednote { font
-
weight: bold; font
-
style: italic; color: rgb(255, 0, 0); }

.changed { color: rgb(255, 0, 0); }

.bartop { border
-
top: 4px solid rgb(51, 102, 153); border
-
bottom: 4px solid rgb(204, 204, 204); }

.barbottom { border
-
top: 4px solid rgb(204
, 204, 204); border
-
bottom: 4px solid rgb(51, 102, 153); }

.collage { float: right; padding: 2px; }

.note { font
-
size: 80%; }

ul { list
-
style: disc inside none; padding
-
left: 0pt; margin
-
left: 0pt; }

ul.number { list
-
style: decimal inside none; }

ul.none {

list
-
style: none inside none; }

.dialin { font
-
family: Helvetica,Arial,sans
-
serif; font
-
size: 11px; color: rgb(102, 102, 102); }

</style>


<style>

hr { color: rgb(255, 255, 255); border
-
style: dashed; border
-
color: rgb(161, 200, 214); border
-
width: 0px 0p
x 1px;
margin: 5px 0px; clear: both; }

</style>


<table align="center" bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" width="800">

<tbody>

<tr>


<td colspan="3" align="center" valign="top">



<table bgcolor="#f0eccf" border="0" cellpaddin
g="0" cellspacing="0">


<tbody>


<tr>


<td colspan="4"><img src="http://cse.csusb.edu/images/banner.jpg"></td>


</tr>


</tbody>


</table>


</td>

</tr>


<tr>


<td width="32">&nbsp;</td>


<td align="left" valign="top" width
="738">


<table border="0" cellpadding="0" cellspacing="0" width="738">


<tbody>


<tr>


<td> <br>

<span style="font
-
family: Arial; font
-
style: normal; font
-
variant: normal; font
-
weight: normal; font
-
size: 14px; line
-
height: normal;
font
-
size
-
adjust: none; font
-
stretch: normal; color: rgb(102, 102, 102);">


[ user@mail ~]$

vi header2


h
eader2
:

</span><br> <span style="color: rgb(93, 158, 195); font
-
size: 12px; line
-
height: 18px;"><br>

<pre>

<br><br>


[ user@mail ~]$

vi mesg

m
esg:

The
School of Computer Science and Engineering, CSUSB, invites you for our annual
Systems Administration
Conference
:<br>

<br>

Please join us in honoring the
best systems administrators of the year in Southern California
<br>

Bring favorite ethnic dish or desser
t. Beverages will be provided.<br>

<br>

--

Invite your friends and family!<br>

<br>

--

You may bring a chair or a blanket.<br>

<br>

<br>

Date: Saturday, June 11, 20
45
<br>

Time: 11:00AM
-
2:00PM<br>

<br>

RSVP by Wednesday, June 8, 20
45
<br>

E
-
mail:
ken
@csusb.e
du<br>

Phone: (909) 537
-
5326<br>


Location: Upper Level soccer fields, North of Lot
-
G<br>

Directions: From University Parkway, turn right on
North park
. Turn<br>

left at second traffic light onto Coyote Drive and then park in Lot G.<br>

<br>

I am looking f
orward to seeing you there.<br>

<br>

<br>

<br>

Ken
Han
,
M
.
S.

,
Sr. Systems Administrator
<br>

School of Computer Science and Engineering<br>

California State University San Bernardino<br>

k
en
@csusb.edu (909) 537
-
5326<br>



[ user@mail ~]$

vi footer


fo
oter:


<hr>


</per>


<br>


</span> </span></td>


</tr>


</tbody>


</table>


<br>


<br>


<br>


</td>


<td width="30">&nbsp;</td>


</tr>


</tbody>


</table>

</font>

</pre>

</body>

</html>


Sending email:

[ user@mail ~]$

send list.txt



Lab 6: Report


What did you learn from this lab?