Jump to page: 1 2 3
Thread overview
Vibemail - extensions for vibe's Mail class to send multi-part emails with attachments
Sep 29, 2015
Sebastiaan Koppe
Sep 29, 2015
Suliman
Sep 29, 2015
Sebastiaan Koppe
Sep 29, 2015
Suliman
Sep 29, 2015
Sebastiaan Koppe
Sep 29, 2015
Russel Winder
Sep 29, 2015
Sebastiaan Koppe
Sep 29, 2015
Adam D. Ruppe
Sep 29, 2015
Daniel Kozak
Sep 29, 2015
Adam D. Ruppe
Sep 29, 2015
Daniel Kozak
Sep 29, 2015
Adam D. Ruppe
Sep 29, 2015
Sebastiaan Koppe
Sep 29, 2015
Adam D. Ruppe
Sep 29, 2015
karabuta
Sep 29, 2015
ponce
Sep 29, 2015
ponce
Sep 30, 2015
rcorre
Oct 04, 2015
Sebastiaan Koppe
Sep 29, 2015
karabuta
Sep 29, 2015
Sebastiaan Koppe
Sep 29, 2015
Robert M. Münch
Sep 29, 2015
Sebastiaan Koppe
Sep 29, 2015
karabuta
September 29, 2015
This library[1] allows you to send multi-part emails with attachments.

```
Mail email = new Mail;
email.headers["Date"] = Clock.currTime().toRFC822DateTimeString();
email.headers["Sender"] = "Domain.com Contact Form ";
email.headers["From"] = "\"Example\" <info@example.com>";
email.headers["To"] = "\"Bas\" <bas@example.com>";
email.headers["Subject"] = "My subject";
import std.stdio : File;
email.setContent(
    mailMixed(
        mailRelated(
            mailAlternative(
                mailHtml("<html><body><center>asdfasdfasdf</center></body></html>"),
                mailText("asdfasdfasdf")
            )
        ),
        mailAttachment(File("test.png","rb"),"image/png","image.png"),
        mailAttachment(cast(immutable(ubyte[]))"You are an idiot!","plain/text","text.txt")
    )
);
sendMail(settings, email);
```

[1] http://code.dlang.org/packages/vibemail
September 29, 2015
Does it's work with anything except localhost?
Could you add example of sending email with gmail?
September 29, 2015
On Tue, 2015-09-29 at 03:53 +0000, Sebastiaan Koppe via Digitalmars-d -announce wrote:
> This library[1] allows you to send multi-part emails with attachments.

This code looks so similar to the equivalent in Python, it is great. Does it need Vibe underneath it though to work, or is this a package that can sit separately and just use sockets to connect to the SMTP server as with Python?

Though I would rather there was no HTML in any email!

> ```
> Mail email = new Mail;
> email.headers["Date"] = Clock.currTime().toRFC822DateTimeString();
> email.headers["Sender"] = "Domain.com Contact Form ";
> email.headers["From"] = "\"Example\" <info@example.com>";
> email.headers["To"] = "\"Bas\" <bas@example.com>";
> email.headers["Subject"] = "My subject";
> import std.stdio : File;
> email.setContent(
>      mailMixed(
>          mailRelated(
>              mailAlternative(
> 
> mailHtml("<html><body><center>asdfasdfasdf</center></body></html>"),
>                  mailText("asdfasdfasdf")
>              )
>          ),
> 
> mailAttachment(File("test.png","rb"),"image/png","image.png"),
>          mailAttachment(cast(immutable(ubyte[]))"You are an
> idiot!","plain/text","text.txt")
>      )
> );
> sendMail(settings, email);
> ```
> 
> [1] http://code.dlang.org/packages/vibemail
-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder



September 29, 2015
On Tuesday, 29 September 2015 at 06:18:32 UTC, Suliman wrote:
> Does it's work with anything except localhost?
> Could you add example of sending email with gmail?

It is in the settings variable. Look at vibe.mail.SMTPClientSettings. http://vibed.org/api/vibe.mail.smtp/SMTPClientSettings

In my tests I used rackspace's mail servers.

```
auto settings = new SMTPClientSettings("secure.emailsrvr.com",587);
settings.authType = SMTPAuthType.login;
settings.connectionType = SMTPConnectionType.startTLS;
settings.tlsValidationMode = TLSPeerValidationMode.requireCert;
settings.username = "info@example.com";
settings.password = "123456789";
```

Replace with whatever gmail has.

The only problem I had was with `settings.tlsValidationMode`. It failed with the certificates so I had to set it to `requireCert`. But I wouldn't do that.
September 29, 2015
Sebastiaan Koppe píše v Út 29. 09. 2015 v 03:53 +0000:
> This library[1] allows you to send multi-part emails with attachments.
> 
> ```
> Mail email = new Mail;
> email.headers["Date"] = Clock.currTime().toRFC822DateTimeString();
> email.headers["Sender"] = "Domain.com Contact Form ";
> email.headers["From"] = "\"Example\" <info@example.com>";
> email.headers["To"] = "\"Bas\" <bas@example.com>";
> email.headers["Subject"] = "My subject";
> import std.stdio : File;
> email.setContent(
>      mailMixed(
>          mailRelated(
>              mailAlternative(
> 
> mailHtml("<html><body><center>asdfasdfasdf</center></body></html>"),
>                  mailText("asdfasdfasdf")
>              )
>          ),
> 
> mailAttachment(File("test.png","rb"),"image/png","image.png"),
>          mailAttachment(cast(immutable(ubyte[]))"You are an
> idiot!","plain/text","text.txt")
>      )
> );
> sendMail(settings, email);
> ```
> 
> [1] http://code.dlang.org/packages/vibemail

Wow, I need something like this 3 weeks ago, but I dont have time to implement this myself, so I end up with phpMailer. Now I can switch my little e-mailing system to Dlang. Thank you.
September 29, 2015
On Tuesday, 29 September 2015 at 07:24:48 UTC, Russel Winder wrote:
> This code looks so similar to the equivalent in Python, it is great. Does it need Vibe underneath it though to work, or is this a package that can sit separately and just use sockets to connect to the SMTP server as with Python?

It only depends on vibe's Mail class.

The only function that interacts with the Mail class is this one:

```
void setContent(MailPart)(Mail email, MailPart part)
	if (isMailPart!MailPart)
{
	foreach(key, value; part.headers)
		email.headers[key] = value;

	import std.conv : text;
	email.bodyText = part.content.text;
}
```

Which is rather trivial to port.

Having said that, I have no need to build my own SMTP client. Vibe does a good job. And there is also a more stand-alone project on code.dlang.org which I forgot the name of.

> Though I would rather there was no HTML in any email!

From http://www.networkworld.com/article/2199390/uc-voip/the-mime-guys--how-two-internet-gurus-changed-e-mail-forever.html?page=3

```
While Freed was concerned about the problems occurring when content moved from one e-mail system to another, "I wanted to be able to send pictures and videos and stuff like that in e-mail," Borenstein says. "And by the way, when people would ask me, 'Why do you care so much about putting media into e-mail?' I always said because someday I'm going to have grandchildren and I want to get pictures of them by e-mail. And people's reaction was to laugh and laugh."

Borenstein started receiving pictures of his twin grandchildren via e-mail in 2009
```

That why we want stuff besides text in our emails.
September 29, 2015
On Tuesday, 29 September 2015 at 09:05:09 UTC, Sebastiaan Koppe wrote:
> That why we want stuff besides text in our emails.

Attachments do pictures better than html bodies though.
September 29, 2015
On Tuesday, 29 September 2015 at 08:54:39 UTC, Daniel Kozak wrote:
> Wow, I need something like this 3 weeks ago, but I dont have time to implement this myself, so I end up with phpMailer. Now I can switch my little e-mailing system to Dlang. Thank you.

If you ever need something in D, ask me first.... there's a good chance I've written it!

https://github.com/adamdruppe/arsd/blob/master/email.d

....there's also a good chance I haven't documented it too though...

but the way mine works is something like:

---
import arsd.email;
void main() {
        auto message = new EmailMessage();
        message.to ~= "destructionator@gmail.com";
        message.from = "test@arsdnet.net";
        message.subject = "test";
        message.setHtmlBody("<img src=\"cid:amazing\" /><b>test</b>");
        message.addAttachment("text/csv", "cool.csv", "whoa,mang");
        message.addAttachment("text/wtf", "whoa.wtf", "WTF\nMAN");
        message.addInlineImage("amazing", "image/png", "black.png",
import("black.png"));
        message.send();
}
---


The send method uses std.net.curl to do the actual sending (the smtp connection information is a default argument to the method.


My lib also has a function:

void email(string to, string subject, string message, string from, RelayInfo mailServer = RelayInfo("smtp://localhost")) {}


for sending a plain text email quickly and easily, similar to PHP's mail function.
September 29, 2015
On 2015-09-29 03:53:44 +0000, Sebastiaan Koppe said:

> This library[1] allows you to send multi-part emails with attachments.
> 
> ```
> Mail email = new Mail;
> email.headers["Date"] = Clock.currTime().toRFC822DateTimeString();
> email.headers["Sender"] = "Domain.com Contact Form ";
> email.headers["From"] = "\"Example\" <info@example.com>";
> email.headers["To"] = "\"Bas\" <bas@example.com>";
> email.headers["Subject"] = "My subject";
> import std.stdio : File;
> email.setContent(
>      mailMixed(
>          mailRelated(
>              mailAlternative(
>                  mailHtml("<html><body><center>asdfasdfasdf</center></body></html>"),
>                  mailText("asdfasdfasdf")
>              )
>          ),
>          mailAttachment(File("test.png","rb"),"image/png","image.png"),
>          mailAttachment(cast(immutable(ubyte[]))"You are an idiot!","plain/text","text.txt")
>      )
> );
> sendMail(settings, email);

Not that I'm to deep into the code nor D but would it be possible to write it somehow like this:

Mail email = new Mail;

email.headers = [
	"Date" Clock...,
	"Sender" ...
]

This would be a much more descriptive approach, which I think makes a lot of sense for such things. And it follows the "dont repeat yourself" pattern.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

September 29, 2015
Adam D.Ruppe píše v Út 29. 09. 2015 v 12:05 +0000:
> On Tuesday, 29 September 2015 at 08:54:39 UTC, Daniel Kozak wrote:
> > Wow, I need something like this 3 weeks ago, but I dont have time to implement this myself, so I end up with phpMailer. Now I can switch my little e-mailing system to Dlang. Thank you.
> 
> If you ever need something in D, ask me first.... there's a good chance I've written it!
> 
> https://github.com/adamdruppe/arsd/blob/master/email.d
> 
> ....there's also a good chance I haven't documented it too though...
> 
> but the way mine works is something like:
> 
> ---
> import arsd.email;
> void main() {
>          auto message = new EmailMessage();
>          message.to ~= "destructionator@gmail.com";
>          message.from = "test@arsdnet.net";
>          message.subject = "test";
>          message.setHtmlBody("<img src=\"cid:amazing\"
> /><b>test</b>");
>          message.addAttachment("text/csv", "cool.csv",
> "whoa,mang");
>          message.addAttachment("text/wtf", "whoa.wtf", "WTF\nMAN");
>          message.addInlineImage("amazing", "image/png",
> "black.png",
> import("black.png"));
>          message.send();
> }
> ---
> 
> 
> The send method uses std.net.curl to do the actual sending (the smtp connection information is a default argument to the method.
> 
> 
> My lib also has a function:
> 
> void email(string to, string subject, string message, string from, RelayInfo mailServer = RelayInfo("smtp://localhost")) {}
> 
> 
> for sending a plain text email quickly and easily, similar to PHP's mail function.

Thanks, I will look at it.

I only look at code.dlang.org. It would be nice to have all of yours stuff on code.dlang.org.




« First   ‹ Prev
1 2 3