We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Getting exception when sending bulk emails

Hai,
In my application when i tried to send bulk emails bu using ssl enabled smtp server settings(like gmail)
an exception is coming…
This is the code that i had used,
MailMessage template = CreateMessage();


TemplateEngine engine = new TemplateEngine(template);
if (General.SelectedSignature > -1)
{
engine.RegisterRoutine(“GetSignature”, new Aspose.Network.Mail.TemplateRoutine(GetSignature));
}
InitializeDt();// filling the data table with values

MailMessageCollection messages = engine.Instantiate(dt); // where dt is data table.
//changed
SmtpClient client = new SmtpClient();
client.Host = smtp.gmail.com;
client.Username = sajeesh@gmail.com;
client.Password = *******;
client.Port = 587;
client.SecurityMode = SmtpSslSecurityMode.Explicit;
client.EnableSsl = true;
try
{
client.BulkSend(messages);
MessageBox.Show(“done”);

}
No emails are sending by using this method,
This is the exception :

Aspose.Network.Mail.SmtpFailedBulkSendException was caught
Message=“At least one E-mail Message failed to deliver.”
Source=“Aspose.Network”
StackTrace:
at Aspose.Network.Mail.SmtpClientBulkSendAgent.xff4c5588fa5a5de3()
at Aspose.Network.Mail.SmtpClient.BulkSend(MailMessageCollection messages)
at My_Project.UserControls.MyCntrlSend.SendMail() in C:\My projects\My_Project\UserControls\MyCntrlSend.cs:line 1362


Could you please send to me a solution for this??
is it possible to send bulk emails using bulkagent method uisng ssl enabled smtp server settings(like gmail)
Regards,
Sajeesh

Hello, Sajeesh,

1. Could you please check the InnerExceptions property of the SmtpFailedBulkSendException? This property will record all of the exception in the email sending. Please post the exception content, then we can investigate the root.

2. The FailedSentMessages property of the SmtpFailedBulkSendException will record all of the messages that cannot be sent.

Thanks


Hai,

This is the inner exception details:
Failed to log on the server with LogIn authentication method.

((System.Exception)((new System.Collections.ArrayList.ArrayListDebugView(((Aspose.Network.Mail.SmtpFailedBulkSendException)(ex)).InnerExceptions)).Items[0])).InnerException.Message
Must issue a STARTTLS command first. y25sm12383984pod.5 (530).

But when i use this code for sending bulk emails using bulkagent method no exception is coming, but emails are not delivering,

MailMessage template = CreateMessage();

TemplateEngine engine = new TemplateEngine(template);

InitializeDt();



MailMessageCollection messages = engine.Instantiate(dt);// filling msg colletion by the values of data table
SmtpClient client = new SmtpClient(smtp.gmail.com, 587, saj@gmail.com, passwod);
client.SecurityMode = SmtpSslSecurityMode.Explicit;
client.EnableSsl = true;
try
{

SmtpClientBulkSendAgent bulkagent = new SmtpClientBulkSendAgent(client);
bulkagent.AddMessages(messages);
bulkagent.Start();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}


private void InitializeDt()
{

string frmName = " ";
dt = new DataTable();
this.dt.Columns.Add(“EmailAddress”, typeof(string));
this.dt.Columns.Add(“DisplayName”, typeof(string));
this.dt.Columns.Add(“FirstName”, typeof(string));
this.dt.Columns.Add(“LastName”, typeof(string));
this.dt.Columns.Add(“Company”, typeof(string));
this.dt.Columns.Add(“FromName”, typeof(string));
this.dt.Columns.Add(“FromEmailAddress”, typeof(string));
this.dt.Columns.Add(“Date”, typeof(string));
this.dt.Columns.Add(“Time”, typeof(string));



this.dt.Rows.Add(new object[] { .EmailId,EL.DisplayName,
.FirstName,LastNameCompany,frmName,.FromEmail Address,
DateTime.Now.Date.ToShortDateString(),DateTime.Now.ToShortTimeString()});

}
Could you please send me the solution for this code,
Regards,
Sajeesh



Hello,

Please send me all of the code, so that I can reproduce the bug locally. I will get back to you ASAP.

Thanks

MailMessage template = CreateMessage();

TemplateEngine engine = new TemplateEngine(template);

InitializeDt();



MailMessageCollection messages = engine.Instantiate(dt);// filling msg colletion by the values of data table
SmtpClient client = new SmtpClient(smtp.gmail.com, 587, saj@gmail.com, passwod);
client.SecurityMode = SmtpSslSecurityMode.Explicit;
client.EnableSsl = true;
try
{

SmtpClientBulkSendAgent bulkagent = new SmtpClientBulkSendAgent(client);
bulkagent.AddMessages(messages);
bulkagent.Start();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}


private void InitializeDt()
{

string frmName = " “;
dt = new DataTable();
this.dt.Columns.Add(“EmailAddress”, typeof(string));
this.dt.Columns.Add(“DisplayName”, typeof(string));
this.dt.Columns.Add(“FirstName”, typeof(string));
this.dt.Columns.Add(“LastName”, typeof(string));
this.dt.Columns.Add(“Company”, typeof(string));
this.dt.Columns.Add(“FromName”, typeof(string));
this.dt.Columns.Add(“FromEmailAddress”, typeof(string));
this.dt.Columns.Add(“Date”, typeof(string));
this.dt.Columns.Add(“Time”, typeof(string));
this.dt.Rows.Add(new object[] {General.FromEI, frmName,frmName,frmName,General.FromCompany,
General.FromEI,DateTime.Now.Date.ToShortDateString(),DateTime.Now.ToShortTimeString()});
foreach (EmailList EL in General.MailList)
{
this.dt.Rows.Add(new object[] { EL.EmailId,EL.DisplayName,
EL.FirstName,EL.LastName,EL.Company,frmName,General.FromEI,
DateTime.Now.Date.ToShortDateString(),DateTime.Now.ToShortTimeString()});
}

}


private MailMessage CreateMessage()
{
MailMessage msg = new MailMessage();
//From Details
if (General.FromName != null) // General is a classs
{

msg.From = new MailAddress(General.FromEI, General.FromName, true);
}
else if (General.FromName == null)
{
msg.From = new MailAddress(General.FromEI);
}

if (General.ReplyToEId != null)
{
msg.ReplyTo = new MailAddress(General.ReplyToEId);
}


msg.To.Add(new MailAddress(”#EmailAddress#", “#DisplayName#”, true));


msg.Subject = General.MsgSubject;

msg.HtmlBody = General.MsgHtmlBody ;




msg.Date = DateTime.Now;


return msg;

}


in this code no exception is coming but mails are not delivered, but when i use this code
try
{
client.BulkSend(messages);
}
INSTEAD OF
try
{
SmtpClientBulkSendAgent bulkagent = new SmtpClientBulkSendAgent(client);

bulkagent.AddMessages(messages);

bulkagent.Start();
}
exception is coming…
Actually i need solution with bulkagent method…
Regards,
Sajeesh

Hello, Sajeesh,

Thanks for the reply.

Our developer is working on this issue. I will get back to you ASAP.

Cheers,

Hello,

Could you please save some email messages to eml and post here? You can just call the MailMessage.Save(string) to save the email message to your disk.

Thanks

I have tried the code posted. It works fine on my computer. You can check it out. Moreover, I need some email messages to reproduce your issue. Please send me some eml files (save by the MailMessage.Save(string)).

Thanks

MailMessage template = new MailMessage();

//add template field to subject
template.Subject = "Hello, #FirstName#";
template.From = new MailAddress("sender", "kyle@gmail.com");
//String returnPath = "kylehuangyu@gmail.com";

template.To.Add(new MailAddress("#Receipt#", true));

//add template field to html body
//use GetSignment as the template routine, which will provide the same signment.
template.HtmlBody = "Dear #FirstName# #LastName#";

//create a new TemplateEngine with the template message.
TemplateEngine engine = new TemplateEngine(template);

//fill a DataTable as data source
DataTable dt = new DataTable();
dt.Columns.Add("Receipt", typeof(string));
dt.Columns.Add("FirstName", typeof(string));
dt.Columns.Add("LastName", typeof(string));
dt.Columns.Add("EmailEventID", typeof(string));
dt.Columns.Add("ReturnPath", typeof(string));
DataRow dr;
dr = dt.NewRow();
dr["Receipt"] = "kyle@hotmail.com";
dr["FirstName"] = "Nancy";
dr["LastName"] = "Davolio";
dr["EmailEventID"] = "80F75AD1-B83A-42D2-AF25-FB250AB3D459";
dr["ReturnPath"] = "wtopia@gmail.com";

dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Receipt"] = "kyle@hotmail.com";
dr["FirstName"] = "Andrew";
dr["LastName"] = "Fuller";
dr["EmailEventID"] = "8C829A6C-AE6D-4A07-ADC0-F71EA0CDF711";
dr["ReturnPath"] = "wtopia@gmail.com";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Receipt"] = "kyle@163.com";
dr["FirstName"] = "Janet";
dr["LastName"] = "Leverling";
dr["EmailEventID"] = "208E1A48-AE6C-4A98-9185-FA35042A5CB5";
dr["ReturnPath"] = "wtopia@gmail.com";
dt.Rows.Add(dr);

MailMessageCollection messages;
try
{
//create the messages from the template and datasource.
messages = engine.Instantiate(dt);

Aspose.Network.Mail.SmtpClient client = new SmtpClient("smtp.gmail.com");

// set your Gmail username

client.Username = "kyle@gmail.com";

// set you Gmail password

client.Password = "XXXX";

// set the port to 587. This is the SSL port of Gmail SMTP server

client.Port = 587;

// set the security mode to explicit

client.SecurityMode = SmtpSslSecurityMode.Explicit;

// enable SSL

client.EnableSsl = true;


SmtpClientBulkSendAgent agent = new SmtpClientBulkSendAgent(client, 5);
agent.AddMessages(messages);
agent.Start();
agent.WaitForIdle();
Console.Read();
}
catch (MailException ex)
{
System.Diagnostics.Debug.Write(ex.ToString());
}

Hai,
I also try the same code:
this is the code that i worked:

MailMessage template = new MailMessage();
template.Subject = “hello,#FirstName#”;
template.From = new MailAddress(“sajeesh007s@yahoo.co.in”);
template.To.Add(new MailAddress("#Receipt#", true));
template.HtmlBody = “Dear #FirstName# #LastName#”;

TemplateEngine engine = new TemplateEngine(template);
DataTable dt = new DataTable();
dt.Columns.Add(“Receipt”, typeof(string));
dt.Columns.Add(“FirstName”, typeof(string));
dt.Columns.Add(“LastName”, typeof(string));
dt.Columns.Add(“EmailEventID”, typeof(string));
dt.Columns.Add(“ReturnPath”, typeof(string));
DataRow dr;
dr = dt.NewRow();
dr[“Receipt”] = “sajeesh007s@gmail.com”;
dr[“FirstName”] = “Sajeesh”;
dr[“LastName”] = “sam”;
dr[“EmailEventID”] = “80F75AD1-B83A-42D2-AF25-FB250AB3D459”;
dr[“ReturnPath”] = “sajeesh007z@gmail.com”;

dt.Rows.Add(dr);
dr = dt.NewRow();
dr[“Receipt”] = “sujithatthoughts@gmail.com”;
dr[“FirstName”] = “Andrew”;
dr[“LastName”] = “Fuller”;
dr[“EmailEventID”] = “8C829A6C-AE6D-4A07-ADC0-F71EA0CDF711”;
dr[“ReturnPath”] = “sajeesh007z@gmail.com”;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[“Receipt”] = “sujithatdevine@gmail.com”;
dr[“FirstName”] = “Janet”;
dr[“LastName”] = “Leverling”;
dr[“EmailEventID”] = “208E1A48-AE6C-4A98-9185-FA35042A5CB5”;
dr[“ReturnPath”] = “sajeesh007z@gmail.com”;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr[“Receipt”] = “sajeesh007z@gmail.com”;
dr[“FirstName”] = “Janet”;
dr[“LastName”] = “Leverling”;
dr[“EmailEventID”] = “208E1A48-AE6C-4A98-9185-FA35042A5CB5”;
dr[“ReturnPath”] = “sajeesh007z@gmail.com”;
dt.Rows.Add(dr);


dr = dt.NewRow();
dr[“Receipt”] = “robins.mca@gmail.com”;
dr[“FirstName”] = “Janet”;
dr[“LastName”] = “Leverling”;
dr[“EmailEventID”] = “208E1A48-AE6C-4A98-9185-FA35042A5CB5”;
dr[“ReturnPath”] = “sajeesh007z@gmail.com”;
dt.Rows.Add(dr);


MailMessageCollection messages;

try
{
messages = engine.Instantiate(dt);

Aspose.Network.Mail.SmtpClient client = new SmtpClient("smtp.gmail.com");



client.Username ="sajeesh007s@gmail.com";



client.Password = ******;


client.Port = 587;



client.SecurityMode = SmtpSslSecurityMode.Explicit;



client.EnableSsl = true;

SmtpClientBulkSendAgent agent = new SmtpClientBulkSendAgent(client, 5);
agent.AddMessages(messages);
agent.Start();

// agent.WaitForIdle(); // for me this unction is not getting
Console.Read();
}
catch (MailException ex)
{
System.Diagnostics.Debug.Write(ex.ToString());
}



This code is working without exception, but emails are not delivering…

My aspose version is

Runtime version:v2.0.50727
File version: 3.8.1.6,

when i tried this code:

MailMessage message = new MailMessage();
message.Subject = “hai”;
message.To.Add("sajeesh007z@gmail.com");
message.From = “sajeesh007s@gmail.com”;
message.HtmlBody = “hai”;


SmtpClient client = new SmtpClient();
client.Username ="sajeesh007s@gmail.com";
client.Password = *****;

client.Port = 587;

client.SecurityMode = SmtpSslSecurityMode.Explicit;

client.EnableSsl = true;
client.Send(message);

The email is delivering…

Is it the problem regrds to the version?
Regards,
Sajeesh




Hello,

Could you please try the latest dll? You can dowload it here:

http://www.aspose.com/community/files/54/utility-components/aspose.network/entry146923.aspx

Hai,
Thanks Now its working,
Regards,
Sajeesh