Use Sendmailr with Windows

Use sendmailR with Windows

You could give the new mailR package a shot: http://cran.r-project.org/web/packages/mailR/index.html

The following call should then work:

send.mail(from = "tal.galili@gmail.com",
to = "tal.galili@gmail.com",
subject = "Subject of the email",
body = "Body of the email",
smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "tal.galili", passwd = "PASSWORD", ssl = TRUE),
authenticate = TRUE,
send = TRUE)

SendmailR on virtual machine

Outlook is mail client, so does sendmailR . I assume you mean, you send mail through your SMTP mail server that your outlook mail client also connect to.

First, check whether you can ping your SMTP mail server from virtual machine. The same SMTP mail server as your outlook.

Second, try telnet from VM ubuntu to your SMTP server e.g.

telnet your-smtp-server 22

If neither works, look for those question about connecting VM to your LAN.

(UPDATE)
For your Windows machine to talk to MYADRESSE.local , there must be a setting in the host file. Go open c:\windows\system32\drivers\etc\hosts, and see whether there is a entry for it.
If the entry show

127.0.0.1  MYADRESSE.local 

This mean you have a SMTP server setting in your windows system. If any other address, e.g. (just example, the address can be varied)

192.168.100.10  MYADDRESS.local

Then 192.168.100.10 is your SMTP server addresss . Then the ping , telnet work show above should use this IP address. e.g. telnet 192.168.100.10... And your SendMailR should use this IP address, not MYADDRESS.local

Sending email in R via outlook

You can use RDCOMClient package to access to COM objects from within R. You can easily access the Application Object (Outlook) and configure it. Here a simple example of sending an email:

library(RDCOMClient)
## init com api
OutApp <- COMCreate("Outlook.Application")
## create an email
outMail = OutApp$CreateItem(0)
## configure email parameter
outMail[["To"]] = "dest@dest.com"
outMail[["subject"]] = "some subject"
outMail[["body"]] = "some body"
## send it
outMail$Send()

Of course, this assumes that you have already install outlook and configure it to send/receive your emails. Adding attachment is quite simple also:

outMail[["Attachments"]]$Add(path_to_attch_file)

sending on behalf of secondary mailbox:

outMail[["SentOnBehalfOfName"]] = "yoursecondary@mail.com"

Sending an email from R using the sendmailR package

Are you able to send email via the command-line?

So, first of all, fire up a Terminal and then

$ echo “Test 123” | mail -s “Test” user@domain.com

Look into /var/log/mail.log, or better use

$ tail -f /var/log/mail.log 

in a different window while you send your email. If you see something like

... setting up TLS connection to smtp.gmail.com[xxx.xx.xxx.xxx]:587
... Trusted TLS connection established to smtp.gmail.com[xxx.xx.xxx.xxx]:587:\
TLSv1 with cipher RC4-MD5 (128/128 bits)

then you succeeded. Otherwise, it means you have to configure you mailing system. I use postfix with Gmail for two years now, and I never had have problem with it. Basically, you need to grab the Equifax certificates, Equifax_Secure_CA.pem from here: http://www.geotrust.com/resources/root-certificates/. (They were using Thawtee certificates before but they changed last year.) Then, assuming you used Gmail,

  1. Create relay_password in /etc/postfix and put a single line like this (with your correct login and password):

    smtp.gmail.com login@gmail.com:password

    then in a Terminal,

    $ sudo postmap /etc/postfix/relay_password 

    to update Postfix lookup table.

  2. Add the certificates in /etc/postfix/certs, or any folder you like, then

    $ sudo c_rehash /etc/postfix/certs/ 

    (i.e., rehash the certificates with Openssl).

  3. Edit /etc/postfix/main.cf so that it includes the following lines (adjust the paths if needed):

    relayhost = smtp.gmail.com:587
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/relay_password
    smtp_sasl_security_options = noanonymous
    smtp_tls_security_level = may
    smtp_tls_CApath = /etc/postfix/certs
    smtp_tls_session_cache_database = btree:/etc/postfix/smtp_scache
    smtp_tls_session_cache_timeout = 3600s
    smtp_tls_loglevel = 1
    tls_random_source = dev:/dev/urandom
  4. Finally, just reload the Postfix process, with e.g.

    $ sudo postfix reload 

    (a combination of start/stop works too).

You can choose a different port for the SMTP, e.g. 465.
It’s still possible to use SASL without TLS (the above steps are basically the same), but in both case the main problem is that your login informations are available in a plan text file... Also, should you want to use your MobileMe account, just replace the Gmail SMTP server with smtp.me.com.

Send authenticated mails via Outlook through R using mailR package

This took me a while to figure out. Try this:

send.mail(from = "username@custom.org",
to = c("recipient1@custom.org", "recipient2@custom.org"),
subject = "Title",
body = "Hello from R.",
authenticate = TRUE,
smtp = list(host.name = "smtp.office365.com",
port = 587,
user.name = "username@custom.org",
passwd = "Pa55w0rd",
tls = TRUE))

It is a common misconception that the port is 25 or 447. I believe port 25 can only be used whenauthenticate = FALSE.

Many sources claim that the correct server is smtp-mail.outlook.com. Perhaps you could try this in the event that the code does not work. Moreover, do not use ssl = TRUE. It has to be tls = TRUE.

Shoutout to Rahul Premraj's answer to this archived 2014 question.

issue using sendemailR

There are two things that need attention in your example:

As @David Arenburg commented, to should contain a valid email address.

The second thing is the smtp server you are using: smtp.gmail.com. This server need authentication which is not supported by sendmailR.

You can use an smtp server that does not require authentication (e.g. the restricted gmail smtp server: aspmx.l.google.com, port 25, see here for details)

The other option is to use the mailR package that allows authentication.

Try something like (of course you have to put valid email addresses and user.name and passwd to work):

library(mailR)
sender <- "SENDER@gmail.com"
recipients <- c("RECIPIENT@gmail.com")
send.mail(from = sender,
to = recipients,
subject="Subject of the email",
body = "Body of the email",
smtp = list(host.name = "smtp.gmail.com", port = 465,
user.name="YOURUSERNAME@gmail.com", passwd="YOURPASSWORD", ssl=TRUE),
authenticate = TRUE,
send = TRUE)

Hope it helps,

alex



Related Topics



Leave a reply



Submit