Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6784223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:57:51+00:00 2026-05-26T16:57:51+00:00

I am desiring to send an email in R with an attachment using gmail.

  • 0

I am desiring to send an email in R with an attachment using gmail. I have found that sendmailR does not work with gmail because it requires authentication (I couldn’t get it to work with gmail so I assume this to be true unless someone tells me I’m wrong , in which case I’ll post the R output and error message for that). I found a code snippet found here (LINK). As the site suggests the code is not formatted to send attachments but I have got it to send an email. I’d like to extend this code to send attachments (in an email correspondence the author of this code was unable to extend the code to send attachments).

I want to send emails with R using gmail. I am a windows 7 user with the 2.14 beta version of R.

The code that sends emails but not attachments:

require(rJython) 
rJython <- rJython() 
rJython$exec( "import smtplib" ) 
rJython$exec("from email.MIMEText import MIMEText") 
rJython$exec("import email.utils") 

mail<-c( 
#Email settings 
"fromaddr = 'bigbird@gmail.com'", 
"toaddrs  = 'oscarthegrouch@gmail.com'", 
"msg = MIMEText('This is the body of the message.')", 
"msg['From'] = email.utils.formataddr(('sender name', fromaddr))", 
"msg['To'] = email.utils.formataddr(('recipient name', toaddrs))", 
"msg['Subject'] = 'Simple test message'", 

#SMTP server credentials 
"username = 'bigbird@gmail.com'", 
"password = 'pw'", 

#Set SMTP server and send email, e.g., google mail SMTP server 
"server = smtplib.SMTP('smtp.gmail.com:587')", 
"server.ehlo()", 
"server.starttls()", 
"server.ehlo()", 
"server.login(username,password)", 
"server.sendmail(fromaddr, toaddrs, msg.as_string())", 
"server.quit()") 

jython.exec(rJython,mail) 

Note this message is cross posted at talkstats.com. I did not receive a reply there (just members telling me they wish they could help). If I receive a workable solution i will also post it there as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:57:52+00:00Added an answer on May 26, 2026 at 4:57 pm

    A response that works and works well is found here:
    http://r.789695.n4.nabble.com/Email-out-of-R-code-td3530671.html

    Thank you to nutterb for an answer from the rhelp list. Thank you to all that tried to assist me and were patient with my ignorance of python.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On more than one occasion I have found myself desiring a variable visibility that
I am desiging a new table that will potentially have 200K rows. I would
Users are desiring that the drop down window of a RadComboBox go up instead
I've a winforms application that is using SQLite database. There is no encryption on
I know 2 ways for desiging an event in C++: 1: Using callbacks: typedef
Our application is JSF2 based and we are desiging a exception handling for that.
I have been programming in Java for the past 2 years and now i
I am using MVVM pattern for my app. The model actually runs a set
I have embedded string resources in my .NET 4.0 project: Strings.resx and Strings.de.resx. In
Is it okay to employ a function that sanitizes the incoming inputs due to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.