If so, it would be great if someone would post a quick howto for
configuring a happs app to send email, whether internally or calling
postfix or whatever.
> If so, it would be great if someone would post a quick howto for
> configuring a happs app to send email, whether internally or calling
> postfix or whatever.
This is a client that I hacked out of the original HAppS. I am sure someone could do better but it should be something for you to chew on at least. Best of all it works!
> > If so, it would be great if someone would post a quick howto for
> > configuring a happs app to send email, whether internally or calling
> > postfix or whatever.
If you already got this message from me than please accept my
apologies for the spam.
This is a client that I hacked out of the original HAppS. I am sure
someone could do better but it should be something for you to chew on
at least. Best of all it works!
hPutLine :: Handle -> String -> IO ()
hPutLine handle line =
do
hPutStr handle $ line
hPutStr handle "\r\n"
hFlush handle
return ()
hGetLn :: Handle -> IO String
hGetLn handle = do
let hGetLn' = do
c <- hGetChar handle
case c of
'\n' -> do return []
'\r' -> do c2 <- hGetChar handle
if c2 == '\n' then return [] else getRest c
_ -> do getRest c
getRest c = do fmap (c:) hGetLn'
line <- hGetLn'
return line
ltrim = dropWhile isSpace
rtrim = reverse.ltrim.reverse
trim = ltrim.rtrim
split :: (a -> Bool) -> [a] -> ([a], [a])
split f s = (left, right)
where
(left,right')=break f s
right = if null right' then [] else tail right'
type Domain = String
data Address = Address {mailBox::String,domain::Domain} deriving
(Ord,Eq)
instance Show Address where
show (Address u d) = u++ '@' :d
instance Read Address where
readsPrec _ s = if isAddr then [(Address userId domain,rest)] else
[]
where
(userId,dr) = split (=='@') $ trim s
(domain, rest) = break(\x-> not $ isAlphaNum x || (x `elem`
"-_.")) dr
isAddr = not $ null userId || null domain
> If so, it would be great if someone would post a quick howto for
> configuring a happs app to send email, whether internally or calling
> postfix or whatever.
> If you already got this message from me than please accept my
> apologies for the spam.
> This is a client that I hacked out of the original HAppS. I am sure
> someone could do better but it should be something for you to chew on
> at least. Best of all it works!
> hGetLn :: Handle -> IO String
> hGetLn handle = do
> let hGetLn' = do
> c <- hGetChar handle
> case c of
> '\n' -> do return []
> '\r' -> do c2 <- hGetChar handle
> if c2 == '\n' then return [] else getRest c
> _ -> do getRest c
> getRest c = do fmap (c:) hGetLn'
> line <- hGetLn'
> return line
> split :: (a -> Bool) -> [a] -> ([a], [a])
> split f s = (left, right)
> where
> (left,right')=break f s
> right = if null right' then [] else tail right'
> type Domain = String
> data Address = Address {mailBox::String,domain::Domain} deriving
> (Ord,Eq)
> instance Show Address where
> show (Address u d) = u++ '@' :d
> instance Read Address where
> readsPrec _ s = if isAddr then [(Address userId domain,rest)] else
> []
> where
> (userId,dr) = split (=='@') $ trim s
> (domain, rest) = break(\x-> not $ isAlphaNum x || (x `elem`
> "-_.")) dr
> isAddr = not $ null userId || null domain
> > If so, it would be great if someone would post a quick howto for
> > configuring a happs app to send email, whether internally or calling
> > postfix or whatever.
> Thanks. It would be great if you could provide a one-line example of
> using hostSend to send mail using, say, gmail as an smtp server.
> Also, for anybody that wants to use this with ghc 6.10.1 you need to
> replace Control.Exception with Control.OldException.
> As soon as I get this working for me I'll hackagize it as part of
> HAppSHelpers.
> thomas.
> On Dec 4, 3:19 pm, parnell <parnell.fl...@ronin-capital.com> wrote:
> > If you already got this message from me than please accept my
> > apologies for the spam.
> > This is a client that I hacked out of the original HAppS. I am sure
> > someone could do better but it should be something for you to chew on
> > at least. Best of all it works!
> > hGetLn :: Handle -> IO String
> > hGetLn handle = do
> > let hGetLn' = do
> > c <- hGetChar handle
> > case c of
> > '\n' -> do return []
> > '\r' -> do c2 <- hGetChar handle
> > if c2 == '\n' then return [] else getRest c
> > _ -> do getRest c
> > getRest c = do fmap (c:) hGetLn'
> > line <- hGetLn'
> > return line
> > split :: (a -> Bool) -> [a] -> ([a], [a])
> > split f s = (left, right)
> > where
> > (left,right')=break f s
> > right = if null right' then [] else tail right'
> > type Domain = String
> > data Address = Address {mailBox::String,domain::Domain} deriving
> > (Ord,Eq)
> > > If so, it would be great if someone would post a quick howto for
> > > configuring a happs app to send email, whether internally or calling
> > > postfix or whatever.
I am sure that you could come up with a better way to create the envelope object. In this example I have hard coded the domain from which and to which I send mails which is probably not to desirable for most people.
-- | This creates an envelope object that is used to send mail.
myenvelope subj mess to = Envelope {
relay = "localhost",
sender = Address "Name of Sender" "Domain" ,
recipients = [Address to "Reciever Domain"],
contents = "Subject: "++ subj ++ "\r\n" ++ mess
}
-- CreateSubject and Create Main message just return Strings from a data set.
(sendEmail (createMainMessage "" "" r) (createSubject (length r) db1) recip addr)
I hope this helps, I will be in 7th heaven once you hackagize this or something like it.
Are you running HAppS with 6.10.1? How has that worked for you?
> -----Original Message-----
> From: HAppS@googlegroups.com [mailto:HAppS@googlegroups.com] On Behalf Of
> tphyahoo
> Sent: Friday, December 05, 2008 11:40 AM
> To: HAppS
> Subject: Re: sending email from happs?
> Parnell,
> Thanks. It would be great if you could provide a one-line example of
> using hostSend to send mail using, say, gmail as an smtp server.
> Also, for anybody that wants to use this with ghc 6.10.1 you need to
> replace Control.Exception with Control.OldException.
> As soon as I get this working for me I'll hackagize it as part of
> HAppSHelpers.
> thomas.
> On Dec 4, 3:19 pm, parnell <parnell.fl...@ronin-capital.com> wrote:
> > If you already got this message from me than please accept my
> > apologies for the spam.
> > This is a client that I hacked out of the original HAppS. I am sure
> > someone could do better but it should be something for you to chew on
> > at least. Best of all it works!
> > hGetLn :: Handle -> IO String
> > hGetLn handle = do
> > let hGetLn' = do
> > c <- hGetChar handle
> > case c of
> > '\n' -> do return []
> > '\r' -> do c2 <- hGetChar handle
> > if c2 == '\n' then return [] else getRest c
> > _ -> do getRest c
> > getRest c = do fmap (c:) hGetLn'
> > line <- hGetLn'
> > return line
> > split :: (a -> Bool) -> [a] -> ([a], [a])
> > split f s = (left, right)
> > where
> > (left,right')=break f s
> > right = if null right' then [] else tail right'
> > type Domain = String
> > data Address = Address {mailBox::String,domain::Domain} deriving
> > (Ord,Eq)
> > > If so, it would be great if someone would post a quick howto for
> > > configuring a happs app to send email, whether internally or calling
> > > postfix or whatever.
> On second thought, I think I just don't understand how this code
> works.
> Does this require having an email server behind a firewall? (Since I
> don't see any authentication.)
> I hate setting up smtp servers -- it should be simple, but because of
> the security issues with spammers, it's not.
> Continuing with my own research...
> t.
> On 5 dec, 18:40, tphyahoo <thomashartm...@googlemail.com> wrote:
> > Parnell,
> > Thanks. It would be great if you could provide a one-line example of
> > using hostSend to send mail using, say, gmail as an smtp server.
> > Also, for anybody that wants to use this with ghc 6.10.1 you need to
> > replace Control.Exception with Control.OldException.
> > As soon as I get this working for me I'll hackagize it as part of
> > HAppSHelpers.
> > thomas.
> > On Dec 4, 3:19 pm, parnell <parnell.fl...@ronin-capital.com> wrote:
> > > If you already got this message from me than please accept my
> > > apologies for the spam.
> > > This is a client that I hacked out of the original HAppS. I am sure
> > > someone could do better but it should be something for you to chew on
> > > at least. Best of all it works!
> > > split :: (a -> Bool) -> [a] -> ([a], [a])
> > > split f s = (left, right)
> > > where
> > > (left,right')=break f s
> > > right = if null right' then [] else tail right'
> > > type Domain = String
> > > data Address = Address {mailBox::String,domain::Domain} deriving
> > > (Ord,Eq)
> > > > If so, it would be great if someone would post a quick howto for
> > > > configuring a happs app to send email, whether internally or calling
> > > > postfix or whatever.
t = sendEmail "test message" "test subject" "tphya...@gmail.com" "???"
Do the first three args seem okay? What should I put for arg 4?
happstutorial on ghc 6.10.1 has worked out for me pretty much without
a hitch.
Oh, there's one problem, the crypto library doesn't install right,
which I submitted a patch for. But nothing major.
I am also looking into http://www.ericstockwell.com/?p=3 as a solution
to sending email from inside webapps without implementing an SMTP
solution in haskell.
thomas.
On Dec 5, 7:01 pm, "Parnell Flynn" <parnell.fl...@ronin-capital.com>
wrote:
> I am sure that you could come up with a better way to create the envelope object. In this example I have hard coded the domain from which and to which I send mails which is probably not to desirable for most people.
> -- | This creates an envelope object that is used to send mail.
> myenvelope subj mess to = Envelope {
> relay = "localhost",
> sender = Address "Name of Sender" "Domain" ,
> recipients = [Address to "Reciever Domain"],
> contents = "Subject: "++ subj ++ "\r\n" ++ mess
> }
> -- CreateSubject and Create Main message just return Strings from a data set.
> (sendEmail (createMainMessage "" "" r) (createSubject (length r) db1) recip addr)
> I hope this helps, I will be in 7th heaven once you hackagize this or something like it.
> Are you running HAppS with 6.10.1? How has that worked for you?
> Cheers,
> Parnell
> > -----Original Message-----
> > From: HAppS@googlegroups.com [mailto:HAppS@googlegroups.com] On Behalf Of
> > tphyahoo
> > Sent: Friday, December 05, 2008 11:40 AM
> > To: HAppS
> > Subject: Re: sending email from happs?
> > Parnell,
> > Thanks. It would be great if you could provide a one-line example of
> > using hostSend to send mail using, say, gmail as an smtp server.
> > Also, for anybody that wants to use this with ghc 6.10.1 you need to
> > replace Control.Exception with Control.OldException.
> > As soon as I get this working for me I'll hackagize it as part of
> > HAppSHelpers.
> > thomas.
> > On Dec 4, 3:19 pm, parnell <parnell.fl...@ronin-capital.com> wrote:
> > > If you already got this message from me than please accept my
> > > apologies for the spam.
> > > This is a client that I hacked out of the original HAppS. I am sure
> > > someone could do better but it should be something for you to chew on
> > > at least. Best of all it works!
> > > split :: (a -> Bool) -> [a] -> ([a], [a])
> > > split f s = (left, right)
> > > where
> > > (left,right')=break f s
> > > right = if null right' then [] else tail right'
> > > type Domain = String
> > > data Address = Address {mailBox::String,domain::Domain} deriving
> > > (Ord,Eq)
> > > > If so, it would be great if someone would post a quick howto for
> > > > configuring a happs app to send email, whether internally or calling
> > > > postfix or whatever.
> t = sendEmail "test message" "test subject" "tphya...@gmail.com" "???"
> Do the first three args seem okay? What should I put for arg 4?
> happstutorial on ghc 6.10.1 has worked out for me pretty much without
> a hitch.
> Oh, there's one problem, the crypto library doesn't install right,
> which I submitted a patch for. But nothing major.
> I am also looking intohttp://www.ericstockwell.com/?p=3as a solution
> to sending email from inside webapps without implementing an SMTP
> solution in haskell.
> thomas.
> On Dec 5, 7:01 pm, "Parnell Flynn" <parnell.fl...@ronin-capital.com>
> wrote:
> > I am sure that you could come up with a better way to create the envelope object. In this example I have hard coded the domain from which and to which I send mails which is probably not to desirable for most people.
> > -- | This creates an envelope object that is used to send mail.
> > myenvelope subj mess to = Envelope {
> > relay = "localhost",
> > sender = Address "Name of Sender" "Domain" ,
> > recipients = [Address to "Reciever Domain"],
> > contents = "Subject: "++ subj ++ "\r\n" ++ mess
> > }
> > -- CreateSubject and Create Main message just return Strings from a data set.
> > (sendEmail (createMainMessage "" "" r) (createSubject (length r) db1) recip addr)
> > I hope this helps, I will be in 7th heaven once you hackagize this or something like it.
> > Are you running HAppS with 6.10.1? How has that worked for you?
> > Cheers,
> > Parnell
> > > -----Original Message-----
> > > From: HAppS@googlegroups.com [mailto:HAppS@googlegroups.com] On Behalf Of
> > > tphyahoo
> > > Sent: Friday, December 05, 2008 11:40 AM
> > > To: HAppS
> > > Subject: Re: sending email from happs?
> > > Parnell,
> > > Thanks. It would be great if you could provide a one-line example of
> > > using hostSend to send mail using, say, gmail as an smtp server.
> > > Also, for anybody that wants to use this with ghc 6.10.1 you need to
> > > replace Control.Exception with Control.OldException.
> > > As soon as I get this working for me I'll hackagize it as part of
> > > HAppSHelpers.
> > > thomas.
> > > On Dec 4, 3:19 pm, parnell <parnell.fl...@ronin-capital.com> wrote:
> > > > If you already got this message from me than please accept my
> > > > apologies for the spam.
> > > > This is a client that I hacked out of the original HAppS. I am sure
> > > > someone could do better but it should be something for you to chew on
> > > > at least. Best of all it works!
> > > > > If so, it would be great if someone would post a quick howto for
> > > > > configuring a happs app to send email, whether internally or calling
> > > > > postfix or whatever.
> > Do the first three args seem okay? What should I put for arg 4?
> > happstutorial on ghc 6.10.1 has worked out for me pretty much without
> > a hitch.
> > Oh, there's one problem, the crypto library doesn't install right,
> > which I submitted a patch for. But nothing major.
> > I am also looking intohttp://www.ericstockwell.com/?p=3asa solution
> > to sending email from inside webapps without implementing an SMTP
> > solution in haskell.
> > thomas.
> > On Dec 5, 7:01 pm, "Parnell Flynn" <parnell.fl...@ronin-capital.com>
> > wrote:
> > > I am sure that you could come up with a better way to create the envelope object. In this example I have hard coded the domain from which and to which I send mails which is probably not to desirable for most people.
> > > -- | This creates an envelope object that is used to send mail.
> > > myenvelope subj mess to = Envelope {
> > > relay = "localhost",
> > > sender = Address "Name of Sender" "Domain" ,
> > > recipients = [Address to "Reciever Domain"],
> > > contents = "Subject: "++ subj ++ "\r\n" ++ mess
> > > }
> > > -- CreateSubject and Create Main message just return Strings from a data set.
> > > (sendEmail (createMainMessage "" "" r) (createSubject (length r) db1) recip addr)
> > > I hope this helps, I will be in 7th heaven once you hackagize this or something like it.
> > > Are you running HAppS with 6.10.1? How has that worked for you?
> > > Cheers,
> > > Parnell
> > > > -----Original Message-----
> > > > From: HAppS@googlegroups.com [mailto:HAppS@googlegroups.com] On Behalf Of
> > > > tphyahoo
> > > > Sent: Friday, December 05, 2008 11:40 AM
> > > > To: HAppS
> > > > Subject: Re: sending email from happs?
> > > > Parnell,
> > > > Thanks. It would be great if you could provide a one-line example of
> > > > using hostSend to send mail using, say, gmail as an smtp server.
> > > > Also, for anybody that wants to use this with ghc 6.10.1 you need to
> > > > replace Control.Exception with Control.OldException.
> > > > As soon as I get this working for me I'll hackagize it as part of
> > > > HAppSHelpers.
> > > > thomas.
> > > > On Dec 4, 3:19 pm, parnell <parnell.fl...@ronin-capital.com> wrote:
> > > > > If you already got this message from me than please accept my
> > > > > apologies for the spam.
> > > > > This is a client that I hacked out of the original HAppS. I am sure
> > > > > someone could do better but it should be something for you to chew on
> > > > > at least. Best of all it works!
> > > > > > If so, it would be great if someone would post a quick howto for
> > > > > > configuring a happs app to send email, whether internally or calling
> > > > > > postfix or whatever.
Quickie instructions for sending yourself gmail over the command line:
**********************
The purpose of this setup is to configure Ubuntu Linux so that you can
send an email with a single command from a bash terminal. The idea
behind this is that once set up to do it, your computer can now
actively alert you (or others) to state changes of your choosing (or
not). Phosphorus and Lime deserves accolades for a great deal of this
procedure. My omissions/simplifications assume that you are setting
this up from scratch, and are only planning to use this through an
existing gmail account.
Now then. You’re going to need a mail client and a SMTP handler. For
these purposes, mailx and msmtp, respectively, will serve you well.
$ sudo apt-get install mailx msmtp
Google’s SMTP service (kindly provided free for gmail account holders)
makes use of Thawte SSL certificates. Since /etc is only writeable by
root (meaning “sudo sudo sudo sudo”), let’s dump and configure them in
~/ like so:
msmtp reads a local config file ( ~/.msmtprc ), containing several
important directives, at runtime. Open a text editor and create it:
$ nano ~/.msmtprc
…then enter the following (customized to your account):
account gmail
auth on
host smtp.gmail.com
port 587
# your email address and password on the next 3 lines...
user yourgmailacco...@gmail.com
password yourpasswordhere
from yourgmailacco...@gmail.com
tls on
tls_starttls on
# tls_trust_file argument is the full path to the certificate
# "myusername" is, uh, your user name
tls_trust_file /home/myusername/.etc/.certs/ThawtePremiumServerCA.crt
maildomain gmail.com
account default : gmail
Save and exit (or in nano’s case, exit and save) your editor, then
give only yourself read/write permissions to the file:
code>$ chmod 600 ~/.msmtprc
Now we configure some runtime parameters for mailx:
$ nano ~/.mailrc
Add the following lines, customized to your gmail account:
set from="yourgmailacco...@gmail.com"
set sendmail="/usr/bin/msmtp"
set message-sendmail-extra-arguments="-a gmail"
Make sure you’ve opened port 587 to the outside world from your
computer through your router!
Save/exit. If you’re so inclined, you can create a preformatted
plaintext file which will serve as the body of the email. As you can
imagine, this opens up all sorts of options to you.
Example:
$ echo "Here's some stuff that will appear in the body of the email."
> /tmp/email_body.txt
$ echo -n "Sent on " >> /tmp/email_body.txt
$ date >> /tmp/email_body.txt
You should be able to fire off an email to exam...@gmail.com using the
syntax shown:
$ mailx -s "O HAI SUBJECT LINE" exam...@gmail.com < /tmp/
email_body.txt
> Quickie instructions for sending yourself gmail over the command line:
> **********************
> The purpose of this setup is to configure Ubuntu Linux so that you can
> send anemailwith a single command from a bash terminal. The idea
> behind this is that once set up to do it, your computer can now
> actively alert you (or others) to state changes of your choosing (or
> not). Phosphorus and Lime deserves accolades for a great deal of this
> procedure. My omissions/simplifications assume that you are setting
> this up from scratch, and are only planning to use this through an
> existing gmail account.
> Now then. You’re going to need a mail client and a SMTP handler. For
> these purposes, mailx and msmtp, respectively, will serve you well.
> $ sudo apt-get install mailx msmtp
> Google’s SMTP service (kindly provided free for gmail account holders)
> makes use of Thawte SSL certificates. Since /etc is only writeable by
> root (meaning “sudo sudo sudo sudo”), let’s dump and configure them in
> ~/ like so:
> msmtp reads a local config file ( ~/.msmtprc ), containing several
> important directives, at runtime. Open a text editor and create it:
> $ nano ~/.msmtprc
> …then enter the following (customized to your account):
> account gmail
> auth on
> host smtp.gmail.com
> port 587
> # youremailaddress and password on the next 3 lines...
> user yourgmailacco...@gmail.com
> password yourpasswordhere
> from yourgmailacco...@gmail.com
> tls on
> tls_starttls on
> # tls_trust_file argument is the full path to the certificate
> # "myusername" is, uh, your user name
> tls_trust_file /home/myusername/.etc/.certs/ThawtePremiumServerCA.crt
> maildomain gmail.com
> account default : gmail
> Save and exit (or in nano’s case, exit and save) your editor, then
> give only yourself read/write permissions to the file:
> code>$ chmod 600 ~/.msmtprc
> Now we configure some runtime parameters for mailx:
> $ nano ~/.mailrc
> Add the following lines, customized to your gmail account:
> set from="yourgmailacco...@gmail.com"
> set sendmail="/usr/bin/msmtp"
> set message-sendmail-extra-arguments="-a gmail"
> Make sure you’ve opened port 587 to the outside world from your
> computer through your router!
> Save/exit. If you’re so inclined, you can create a preformatted
> plaintext file which will serve as the body of theemail. As you can
> imagine, this opens up all sorts of options to you.
> Example:
> $ echo "Here's some stuff that will appear in the body of theemail."> /tmp/email_body.txt
> $ echo -n "Sent on " >> /tmp/email_body.txt
> $ date >> /tmp/email_body.txt
> You should be able to fire off anemailto exam...@gmail.com using the
> syntax shown:
> $ mailx -s "O HAI SUBJECT LINE" exam...@gmail.com < /tmp/
> email_body.txt