April 10
On Tuesday, 10 April 2018 at 15:10:44 UTC, Vino wrote:
> The variable "to" is of type string[] but we need it as Array!string
> The variable "Subject" but we need it as Array!string.

You'll have to convert them yourself if that is a must, but why would you need that?
April 12
On Tuesday, 10 April 2018 at 15:18:19 UTC, Adam D. Ruppe wrote:
> On Tuesday, 10 April 2018 at 15:10:44 UTC, Vino wrote:
>> The variable "to" is of type string[] but we need it as Array!string
>> The variable "Subject" but we need it as Array!string.
>
> You'll have to convert them yourself if that is a must, but why would you need that?

Hi Adam,

 I tried to replicate your code with what is required for me, and was able to successed 90% and stuck, can you please help me.

Using the below code are are able to receive the mail with the attachment, but the content of the attachment contains the Body text of the mail(Body1") rather than the original text and the mail body is empty, not sure where is the issue.

Code:
import std.net.curl;
pragma(lib, "curl");
import std.format;
import std.container.array;
import std.stdio;
import std.path;
import std.file;

struct RelayInfo { string server; }
struct MimeAttachment { string type; string filename; const(void)[] content; string id; }

class EmailMessage {

Array!string To, Body, headers;
string From, Subject, msg;

override string toString ()
{
	string T = "%-(%s,  %)".format(To[]); string B = "%-(%s,  %)".format(Body[]);
	headers.insertBack("To: " ~ T);
	headers.insertBack("From: " ~ From);
	headers.insertBack("Subject: " ~ Subject);
	headers.insertBack("MIME-Version: 1.0");
    	msg.reserve(Body.length + 1024);
	foreach(header; headers) { msg ~= header ~ "\r\n"; }
	if(msg.length > 0) { msg ~= "\r\n"; msg ~= B; }
	
	return(msg);
}

const(MimeAttachment)[] attachments;

void addAttachment(string Fname, ) {
string mimeType = "text/plain";
string filename = baseName(Fname);
void[] content = read(Fname);
string id = null;

headers.insertBack("Content-Disposition: attachment; filename=\""~ filename ~"\"");
headers.insertBack("Content-ID: <" ~ id ~ ">");
headers.insertBack("Content-Type: text/plain; charset=UTF-8; file=" ~ filename);
attachments ~= MimeAttachment(mimeType, filename, content, id);
}

void send (RelayInfo mailServer = RelayInfo("smtp://localhost")) {
auto smtp = SMTP(mailServer.server);
string T = "%-(%s,  %)".format(To[]);
smtp.mailTo = T;
smtp.mailFrom = From;
smtp.message = toString;
smtp.perform();	
}
}

void main () {
string Filename = "D:\\DScript\\Tmailconfig.txt";
auto message = new EmailMessage();
message.To ~= "vino@xxx.com";
message.From = "Server@hosting.com";
message.Subject = "Test";
message.Body ~= "Body1";
message.addAttachment(Filename));
message.send(RelayInfo("smtp://smtp.awk.sed.com"));
}

From,
Vino.B
April 12
On Thursday, 12 April 2018 at 15:58:33 UTC, Vino wrote:
>  I tried to replicate your code with what is required for me

I still wanna know: why use Array instead of regular arrays?

> Using the below code are are able to receive the mail with the attachment, but the content of the attachment contains the Body text of the mail(Body1") rather than the original text and the mail body is empty, not sure where is the issue.

You didn't add the attachment text.

You see how my toString http://dpldocs.info/experimental-docs/source/arsd.email.d.html#L108

includes a loop over the attachments?


http://dpldocs.info/experimental-docs/source/arsd.email.d.html#L183


Attachments need to be serialized in MIME format:
http://dpldocs.info/experimental-docs/source/arsd.email.d.html#L521


I didn't even do it perfectly there lol but it is good enough.


> override string toString ()
> {
> 	string T = "%-(%s,  %)".format(To[]); string B = "%-(%s,  %)".format(Body[]);
> 	headers.insertBack("To: " ~ T);
> 	headers.insertBack("From: " ~ From);
> 	headers.insertBack("Subject: " ~ Subject);
> 	headers.insertBack("MIME-Version: 1.0");
>     	msg.reserve(Body.length + 1024);
> 	foreach(header; headers) { msg ~= header ~ "\r\n"; }
> 	if(msg.length > 0) { msg ~= "\r\n"; msg ~= B; }
> 	
> 	return(msg);
> }



But you didn't even put the attachments in the string at all.

Next ›   Last »
1 2