我正在尝试为本地乐队简报设置此脚本。Perl - 如何从头部的FROM部分获取电子邮件地址?
目前,有人发送一封电子邮件,其中包含要添加的请求,我们将其手动添加到我设置的通讯邮件程序中。 (这工作很好,谢谢我在这里找到的帮助!)
现在的意图是让我的脚本登录到我为我们的服务器上的列表设置的电子邮件帐户,获取信息以自动添加电子邮件。
我知道有一堆应用程序可以做到这一点,但我想了解自己。
我已经有“添加到列表”时,有一个电子邮件地址从标题下方的返回(从)工作,但是,有时头(从)是一个名称,而不是电子邮件地址(eg "persons name" is returned from persons name<[email protected]> but, not the <[email protected]>
。)
现在,我不是沉迷于下面的方法,但是,它着名... ...的一个点。
我阅读了关于这些模块的所有文档,没有任何我能找到的东西在那里得到电子邮件。
有人可以帮我吗?详细的例子非常感谢,因为我正在努力学习Perl。
#!/usr/bin/perl -w
##########
use CGI;
use Net::IMAP::Simple;
use Email::Simple;
use IO::Socket::SSL; #optional i think if no ssl is needed
use strict;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
######################################################
# fill in your details here
my $username = '#########';
my $password = '#############';
my $mailhost = '##############';
#######################################################
print CGI::header();
# Connect
my $imap = Net::IMAP::Simple->new($mailhost, port=> 143, use_ssl => 0,) || die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n";
# Log in
if (!$imap->login($username, $password)) {
print STDERR "Login failed: " . $imap->errstr . "\n";
exit(64);
}
# Look in the the INBOX
my $nm = $imap->select('INBOX');
# How many messages are there?
my ($unseen, $recent, $num_messages) = $imap->status();
print "unseen: $unseen, <br />recent: $recent, <br />total: $num_messages<br />\n\n";
## Iterate through unseen messages
for (my $i = 1 ; $i <= $nm ; $i++) {
if ($imap->seen($i)) {
my $es = Email::Simple->new(join '', @{ $imap->top($i) });
printf("[%03d] %s\n\t%s\n", $i, $es->header('From'), $es->header('Subject'));
print "<br />";
next;
}## in the long version these are pushed into different arrays for experimenting purposes
else {
my $es = Email::Simple->new(join '', @{ $imap->top($i) });
printf("[%03d] %s\n\t%s\n", $i, $es->header('From'), $es->header('Subject'));
print "<br />";
}
}
# Disconnect
$imap->quit;
exit;
谢谢! my $ line = $ es-> header('From');我的@addresses = Email :: Address-> parse($ line);打印$地址[0] - >地址; – DulcimerDude 2010-11-10 16:54:09
谢谢 - 谢谢 - 谢谢!完善... – DulcimerDude 2010-11-10 17:01:27