Saturday, February 22, 2014

Adding an Attachment to an Email and Sending It: PERL

        my ($self) = @_;

        my $boundary = 'frontier';
        
        my $emailAddress = $self->{emailAddress};
        
        my $subject = "Door2Door-DryCleaning: Receipt for Order";
    
        my $body = "Please see the attached file for your receipt.  Thank you for using Door2Door Dry Cleaning.  We appreciate your business.
        <br><br>With regards,<br><br>Door2Door-DryCleaning.com<br><br>";
    
        my $smtp = new Net::SMTP::TLS(
        'smtp.gmail.com',
        Port    => 587,
        User    => 'curtis.sumpter@gmail.com',
        Password=> 'gwpkuuqjdlxbwvzl',
        Timeout => 30
        );
        
        my $fileName = $self->{fileName};
        
        my $data_file = "/home/users/web/b2295/ipg.goformecom/test/$fileName";
        
        $smtp->mail('curtis.sumpter@gmail.com');
    
        
#print MYFILE "Check Point 2\n";
        
    #  -- Enter recipient mails addresses below --
        $smtp->recipient($emailAddress);
        
        $smtp->data();
        
        my $msg = MIME::Lite->new(
        From    => 'curtis.sumpter@gmail.com',
        To      => "$emailAddress",
        Subject => $subject,
        Type    => 'multipart/signed'
        );
    
        $msg->attach(
        Type    => 'application/rtf',
        Path    => "$fileName",
        Filename    => "$fileName",
        Disposition => 'attachment'
        );
        
        $msg->attach(
        Type => 'text/html',
        Data => "$body"
        );

        $smtp->datasend($msg->as_string);
        
        $smtp->dataend();
        $smtp->quit;
        
        eval{$smtp->quit};
    
        return 0 if $@;
    

        return 1;

No comments:

Post a Comment