MIMEMultipart, MIMEText, MIMEBase, and payloads for sending email with file attachment in Python

E-mail messages An e-mail message consists of headers (e.g. “From”, “To”, “Subject” etc.) and body (see RFC 822, section 3.1). The body of the message is, by default, treated as plain ASCII text. MIME (RFC 2045, RFC 2046, RFC 2047, RFC 2048, RFC 2049) defines extensions which allow specifying different types of email content. One … Read more

Reading email (from gmail) in emacs 24

After trying many ways, I now use offlineimap to sync messages between my machine and the google server. Gnus then reads messages from the local machine. Postfix is used to send messages to the gmail smtp server. Virtues of this setup: reading/sending email does not involve waiting for servers while in gnus (fast), can read/send … Read more

A simple SMTP server (in Python)

Take a look at this SMTP sink server: from __future__ import print_function from datetime import datetime import asyncore from smtpd import SMTPServer class EmlServer(SMTPServer): no = 0 def process_message(self, peer, mailfrom, rcpttos, data): filename=”%s-%d.eml” % (datetime.now().strftime(‘%Y%m%d%H%M%S’), self.no) f = open(filename, ‘w’) f.write(data) f.close print(‘%s saved.’ % filename) self.no += 1 def run(): # start the … Read more

SMTP AUTH extension not supported by server

a connection is required before login and sendemail. server = smtplib.SMTP(‘smtp.example.com’, 25) server.connect(“smtp.example.com”,465) server.ehlo() server.starttls() server.ehlo() server.login(fromaddr, “password”) text = msg.as_string() server.sendmail(fromaddr, toaddr, text) server.quit()

How to send utf-8 e-mail?

You should just add ‘utf-8’ argument to your MIMEText calls (it assumes ‘us-ascii’ by default). For example: # -*- encoding: utf-8 -*- from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText msg = MIMEMultipart(“alternative”) msg[“Subject”] = u’テストメール’ part1 = MIMEText(u’\u3053\u3093\u306b\u3061\u306f\u3001\u4e16\u754c\uff01\n’, “plain”, “utf-8”) msg.attach(part1) print msg.as_string().encode(‘ascii’)

Attach a file from MemoryStream to a MailMessage in C#

Here is the sample code. System.IO.MemoryStream ms = new System.IO.MemoryStream(); System.IO.StreamWriter writer = new System.IO.StreamWriter(ms); writer.Write(“Hello its my sample file”); writer.Flush(); writer.Dispose(); ms.Position = 0; System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Text.Plain); System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(ms, ct); attach.ContentDisposition.FileName = “myFile.txt”; // I guess you know how to send email with an attachment // after sending email … Read more

How can I use a local SMTP server when developing on Windows 7? [closed]

If you are developing in ASP.net using the built-in mail libraries, a lesser-known configuration setting is to use the following: <configuration> . . . more config stuff here . . . <system.net> <mailSettings> <smtp deliveryMethod=”SpecifiedPickupDirectory” from=”noreply@testdomain.org”> <specifiedPickupDirectory pickupDirectoryLocation=”c:\smtp\”/> </smtp> </mailSettings> </system.net> </configuration> All your application generated emails will be dumped into this directory during development. … Read more

How to send email via smtp with Ruby’s mail gem?

From http://lindsaar.net/2010/3/15/how_to_use_mail_and_actionmailer_3_with_gmail_smtp To send out via GMail, you need to configure the Mail::SMTP class to have the correct values, so to try this out, open up IRB and type the following: require ‘mail’ options = { :address => “smtp.gmail.com”, :port => 587, :domain => ‘your.host.name’, :user_name => ‘<username>’, :password => ‘<password>’, :authentication => ‘plain’, :enable_starttls_auto … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)