Testing email sending in Django [closed]

Django test framework has some built in helpers to aid you with testing e-mail service. Example from docs (short version): from django.core import mail from django.test import TestCase class EmailTest(TestCase): def test_send_email(self): mail.send_mail(‘Subject here’, ‘Here is the message.’, ‘from@example.com’, [‘to@example.com’], fail_silently=False) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, ‘Subject here’)

Content Transfer Encoding 7bit or 8 bit

It can be a bit dense to read, but the “Content-Transfer-Encoding” section of RFC 1341 has all of the details: http://www.w3.org/Protocols/rfc1341/5_Content-Transfer-Encoding.html The situation kinda goes from bad to worse. Here’s my summary: Background SMTP, by definition (RFC 821), limits mail to lines of 1000 characters of 7 bits each. That means that none of the … Read more

Sending emails with Javascript

The way I’m doing it now is basically like this: The HTML: <textarea id=”myText”> Lorem ipsum… </textarea> <button onclick=”sendMail(); return false”>Send</button> The Javascript: function sendMail() { var link = “mailto:me@example.com” + “?cc=myCCaddress@example.com” + “&subject=” + encodeURIComponent(“This is my subject”) + “&body=” + encodeURIComponent(document.getElementById(‘myText’).value) ; window.location.href = link; } This, surprisingly, works rather well. The only … Read more

Sending email with attachments from C#, attachments arrive as Part 1.2 in Thunderbird

Simple code to send email with attachement. source: http://www.coding-issues.com/2012/11/sending-email-with-attachments-from-c.html using System.Net; using System.Net.Mail; public void email_send() { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient(“smtp.gmail.com”); mail.From = new MailAddress(“your mail@gmail.com”); mail.To.Add(“to_mail@gmail.com”); mail.Subject = “Test Mail – 1”; mail.Body = “mail with attachment”; System.Net.Mail.Attachment attachment; attachment = new System.Net.Mail.Attachment(“c:/textfile.txt”); mail.Attachments.Add(attachment); SmtpServer.Port = 587; SmtpServer.Credentials … Read more

Generating HTML email body in C#

You can use the MailDefinition class. This is how you use it: MailDefinition md = new MailDefinition(); md.From = “test@domain.example”; md.IsBodyHtml = true; md.Subject = “Test of MailDefinition”; ListDictionary replacements = new ListDictionary(); replacements.Add(“{name}”, “Martin”); replacements.Add(“{country}”, “Denmark”); string body = “<div>Hello {name} You’re from {country}.</div>”; MailMessage msg = md.CreateMailMessage(“you@anywhere.example”, replacements, body, new System.Web.UI.Control()); Also, I’ve … Read more

base64 encoded images in email signatures

The image should be embedded in the message as an attachment like this: –boundary Content-Type: image/png; name=”https://stackoverflow.com/questions/9110091/sig.png” Content-Disposition: inline; filename=”https://stackoverflow.com/questions/9110091/sig.png” Content-Transfer-Encoding: base64 Content-ID: <0123456789> Content-Location: sig.png base64 data –boundary And, the HTML part would reference the image like this: <img src=”https://stackoverflow.com/questions/9110091/cid:0123456789″> In some clients, src=”https://stackoverflow.com/questions/9110091/sig.png” will work too. You’d basically have a multipart/mixed, multipart/alternative, multipart/related … Read more

Send email using Java

The following code works very well with Google SMTP server. You need to supply your Google username and password. import com.sun.mail.smtp.SMTPTransport; import java.security.Security; import java.util.Date; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; /** * * @author doraemon */ public class GoogleMail { private GoogleMail() { } /** * … Read more

How do I preview emails in Rails?

Action Mailer now has a built in way of previewing emails in Rails 4.1. For example, check this out: # located in test/mailers/previews/notifier_mailer_preview.rb class NotifierPreview < ActionMailer::Preview # Accessible from http://localhost:3000/rails/mailers/notifier/welcome def welcome Notifier.welcome(User.first) end end

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