YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Tag as favorite
Problem with recipients and attachments
Aqualung
#1 Posted : Friday, July 30, 2010 11:40:10 AM
Rank: Newbie

Medals:

Groups: Member
Joined: 7/30/2010
Posts: 5
Points: 15

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hi,
i'm new to your code. I'm trying to send an email and i have no problem except to CC, BCC recipients and attachments...

In the sent mail i have Cc and Bcc address, but the mail aren't sent to these kind of recipients. I added them in the same way as the to address:

message.To = new Mail_t_AddressList ();
for (int ii=0;ii<_mailTO.Count;ii++)
{
message.To.Add (new Mail_t_Mailbox (_mailTO[ii].DisplayName, _mailTO[ii].Address));
}
message.Cc = new Mail_t_AddressList ();
for (int ii=0;ii<_mailCC.Count;ii++)
{
message.Cc.Add (new Mail_t_Mailbox (_mailCC[ii].DisplayName, _mailCC[ii].Address));
}
message.Bcc = new Mail_t_AddressList ();
for (int ii=0;ii<_mailBCC.Count;ii++)
{
message.Bcc.Add (new Mail_t_Mailbox (_mailBCC[ii].DisplayName, _mailBCC[ii].Address));
}

Other some data... before sending the message, the message object contains to, cc and bcc address properly. The mail is correctly sent to the TO recipient. The CC and The BCC don't receive any mail, but in the mail details that i can view in gmail, i see To: mytoAddress, CC:myccAddress and, very strange, bcc: mybccAddress (!!!)

sorry... the attachments work very well


Thank You

Bracco
ivx
#2 Posted : Friday, July 30, 2010 2:18:04 PM
Rank: Administration

Medals:

Groups: Administration
Joined: 9/15/2006
Posts: 1,278
Points: 3,707

Thanks: 0 times
Was thanked: 13 time(s) in 13 post(s)
Hi,

You should look MailMesssageExamples.zip:
http://www.lumisoft.ee/l...load/downloads/Examples/
Aqualung
#3 Posted : Friday, July 30, 2010 4:43:28 PM
Rank: Newbie

Medals:

Groups: Member
Joined: 7/30/2010
Posts: 5
Points: 15

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Thank you for your immediate reply.

Sorry, i looked at the MailMessageExamples.zip code before my post, but i couldn't find any code to add cc and bcc recipients to the message (i did that correctly my way and the message objects contains exactly the cc and the bcc recipients i added with the message.xx.add method).

The problem is that the cc and bcc are ignored by the SendMessage Method. Before the call, I add the TO recipient to the SMTP_Client.RcpTo, but i don't know how to add the cc and the bcc recipients to the object or, in another way, i don't know how to send a message that uses the message objects properties directly.

Thank you

Bracco
ivx
#4 Posted : Saturday, July 31, 2010 11:07:42 AM
Rank: Administration

Medals:

Groups: Administration
Joined: 9/15/2006
Posts: 1,278
Points: 3,707

Thanks: 0 times
Was thanked: 13 time(s) in 13 post(s)

How you send message exactly ?
Aqualung
#5 Posted : Monday, August 02, 2010 9:40:25 AM
Rank: Newbie

Medals:

Groups: Member
Joined: 7/30/2010
Posts: 5
Points: 15

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Yes, i think i sent the message exactly. I have no problem to receive message and to read it. The only problem is that the Cc and Bcc recipients are not set and, this is very strange, in my gmail account i can see cc: xxxxx and bcc: xxxx like normal text and not in the recipients zone.

Probably i wrongly set them, but i didn't see any method in smtp_client object to set these one and in the message objects they're set exactly like all other parts of the message.

Thank you

Bracco
Aqualung
#6 Posted : Friday, August 06, 2010 11:25:36 AM
Rank: Newbie

Medals:

Groups: Member
Joined: 7/30/2010
Posts: 5
Points: 15

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Sorry, i was not there for a week... Here is the code i use to send the message:

Mail_Message message = new Mail_Message ();
message.MimeVersion = "1.0";
message.MessageID = MIME_Utils.CreateMessageID ();
message.Date = DateTime.Now;
message.From = new Mail_t_MailboxList ();
message.From.Add (new Mail_t_Mailbox (_fromname, _frommail));
message.To = new Mail_t_AddressList ();

// -->> _mailTO, _mailCC and _mailBCC are Arraylist objects containing couples <displayname>-<mailaddress>
for (int ii=0;ii<_mailTO.Count;ii++)
{
message.To.Add (new Mail_t_Mailbox (_mailTO[ii].DisplayName, _mailTO[ii].Address));
}
message.Cc = new Mail_t_AddressList ();
for (int ii=0;ii<_mailCC.Count;ii++)
{
message.Cc.Add (new Mail_t_Mailbox (_mailCC[ii].DisplayName, _mailCC[ii].Address));
}
message.Bcc = new Mail_t_AddressList ();
for (int ii=0;ii<_mailBCC.Count;ii++)
{
message.Bcc.Add (new Mail_t_Mailbox (_mailBCC[ii].DisplayName, _mailBCC[ii].Address));
}

message.Subject = _mailsubject;

// multipart/mixed
MIME_h_ContentType contentType_multipartMixed = new MIME_h_ContentType (MIME_MediaTypes.Multipart.related);
contentType_multipartMixed.Param_Boundary = Guid.NewGuid ().ToString ().Replace ('-', '.');
MIME_b_MultipartRelated multipartMixed = new MIME_b_MultipartRelated (contentType_multipartMixed);
message.Body = multipartMixed;

// multipart/alternative
MIME_Entity entity_multipartAlternative = new MIME_Entity ();
MIME_h_ContentType contentType_multipartAlternative = new MIME_h_ContentType (MIME_MediaTypes.Multipart.alternative);
contentType_multipartAlternative.Param_Boundary = Guid.NewGuid ().ToString ().Replace ('-', '.');
MIME_b_MultipartAlternative multipartAlternative = new MIME_b_MultipartAlternative (contentType_multipartAlternative);
entity_multipartAlternative.Body = multipartAlternative;
multipartMixed.BodyParts.Add (entity_multipartAlternative);

if (_bodyformat == MsgFormat.Text)
{
// text/plain
MIME_Entity entity_text_plain = new MIME_Entity ();
MIME_b_Text text_plain = new MIME_b_Text (MIME_MediaTypes.Text.plain);
entity_text_plain.Body = text_plain;
text_plain.SetText (MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, _mailbody);
multipartAlternative.BodyParts.Add (entity_text_plain);
}
else
{
// text/html
MIME_Entity entity_text_html = new MIME_Entity ();
MIME_b_Text text_html = new MIME_b_Text (MIME_MediaTypes.Text.html);
entity_text_html.Body = text_html;
text_html.SetText (MIME_TransferEncodings.SevenBit, Encoding.UTF8, _mailbody);
multipartAlternative.BodyParts.Add (entity_text_html);
}

message.ReplyTo = new Mail_t_AddressList ();
message.ReplyTo.Add (new Mail_t_Mailbox (null, _replyTO));

// -->> _mailAttachments is an Arraylist object containing attachments to add
for (int ii=0;ii<_mailAttachments.Count;ii++)
{
multipartMixed.BodyParts.Add (Mail_Message.CreateAttachment (_mailAttachments[ii].ToString ()));
}


switch (_mailpriority)
{
case MailPriority.High:
message.Priority = "urgent";
break;
case MailPriority.Low:
message.Priority = "non-urgent";
break;
default:
message.Priority = "normal";
break;
}

using (MemoryStream _mstr = new MemoryStream ())
{
message.ToStream (_mstr, null, null);
_mstr.Position = 0;
using (SMTP_Client oSMTP = new SMTP_Client ())
{
oSMTP.Connect (_servername, _serverport, _useSSL);
oSMTP.Authenticate (_authuser, _authpwd);

oSMTP.MailFrom (((Mail_t_Mailbox) message.From[0]).Address, _mstr.Length);
foreach (Mail_t_Address to in message.To)
{
oSMTP.RcptTo (((Mail_t_Mailbox) to).Address);
}

oSMTP.SendMessage (_mstr);
oSMTP.Disconnect ();
}
}

Thank you in advance

Bracco

ivx
#7 Posted : Monday, August 09, 2010 10:07:39 AM
Rank: Administration

Medals:

Groups: Administration
Joined: 9/15/2006
Posts: 1,278
Points: 3,707

Thanks: 0 times
Was thanked: 13 time(s) in 13 post(s)


You need to add cc/bcc to RcTo command.
Current SendMessage(Stream) won't analyase message body, it just sends it.


You should use
public static void QuickSendSmartHost(string host,int port,bool ssl,Mail_Message message)

If you wan't fast automatic sending.
Aqualung
#8 Posted : Monday, August 09, 2010 7:42:14 PM
Rank: Newbie

Medals:

Groups: Member
Joined: 7/30/2010
Posts: 5
Points: 15

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Thank you,
i modified the code to add these lines:

foreach (Mail_t_Address cc in message.Cc)
{
oSMTP.RcptTo (((Mail_t_Mailbox) cc).Address);
}

foreach (Mail_t_Address bcc in message.Bcc)
{
oSMTP.RcptTo (((Mail_t_Mailbox) bcc).Address);
}

The CC recipient works fine... the BCC seems to have some problem: the mail to the bcc address is not sent and in the mail received to the first recipient (TO) there's a line that says to:<address_to>, <address_cc> (correctly), but also reports bcc:<address_bcc>.

There's something wrong in my code or with the SendMessage method i can't send bcc recipients? is better to use the QuickSendSmartHost method?

Thank you
ivx
#9 Posted : Tuesday, August 10, 2010 8:01:27 AM
Rank: Administration

Medals:

Groups: Administration
Joined: 9/15/2006
Posts: 1,278
Points: 3,707

Thanks: 0 times
Was thanked: 13 time(s) in 13 post(s)

Your last code should send also as needed.
As said, SendMessage won't parse message and use any address of it.

Only quicksend does.
Users browsing this topic
Guest
Tag as favorite
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

SoClean Theme By Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 RC1 | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.110 seconds.