|
Hi, It's me again. Since last question I have written a biggest program, and I have another problem. When I use your Net to send mails, it takes 100% of processor, computer works very slow. When sending is ended, than everything is as usual. This is a big problem for me becouse myprogram sends mostly huge messages with attachment only. Do you have any idea what should I do with it? Should it be in that way? Did you notice it?
|
|
|
|
|
Hi,
Thats not so simple to say ... it depends on your code and how many messages sent conccurently.
|
|
|
|
|
I send only one message concurrently.
Maybe I should not use SMTP_Client.QuickSendSmartHost(...). I seams to be created for fast, small messages. What do you think? Here is the code I use, it's simple:
string To = "to@host.pl";
string Subject = "My thema";
string Patch = @"Path to my file";
string Host = "mail.host.pl";
int Port = 587;
string User = "user";
string Password = "pass";
string Address = "user@host.pl";
Mail_Message message = createMessageAttOnly(To, Subject, Patch);
IO.MemoryStream msgStr = new IO.MemoryStream();
message.ToStream(msgStr, null, null);
msgStr.Seek(0, IO.SeekOrigin.Begin);
SMTP_Client.QuickSendSmartHost(null, Host, Port, false, User, Password, Address,
new string[] { To }, msgStr);
I use your method to create message att only so i don't paste it here...
I'm sory I ask you so many questions, but I'm about ending my program when I deal with that problem. Really thank you for help.
|
|
|
|
|
How big is message in bytes ?
>SMTP_Client.QuickSendSmartHost
Does this method raises CPU usage ?
How long is CPU usage up ?
|
|
|
|
|
This time stream Length = 1264722 in bytes. But it doesn't metter. Small, big, it's allways the same. Sometimes(when att is empty or very small) it just doesnt have enough time to achieve 100% becouse sending ends.
Yes, this method raises CPU usage.
All the time when method is working.
|
|
|
|
|
It depends on execution time, if it's just a little time it's ok.
You can measure time.
DateTime start = DateTime.Now;
// Code
Console.WriteLine("-----------" + (DateTime.Now - start).TotalMilliseconds + "----------------");
Or message box instead console on widows forms.
|
|
|
|
|
Execution time of QuickSendSmartHost? When sending file I mentioned above, one with Length = 1264722 it took 12250 miliseconds, and all the time CPU usage was almost 100%. Of course when I send bigger file(like 10,20,50MB) it takes proportionaly more time. What now? Is that right?
|
|
|
|
|
>1264722 it took 12250
That may be ok.
But i can say if 10mb message takes full CPU for 10 seconds, thats not ok.
For big messages exec time may be depend on network upload speed, but then CPU utlization must not be high.
|
|
|
|
|
Yes, that's right. So I undearstand the code I have written above works fine on your computer? Speed depends on internet speed and it doesn't take 100% of CPU usage? I have tried it on 2 computers. It's allways the same. Even if I dont use it in my program(which could probably be the reason of high CPU usage), but in new, totally clear project, just one button, and code above.
|
|
|
|
|
I dont exactly get waht yuo mean ...
But ...
Give me message you try (for example ca 3 MB) give your result exec time and CPU usage of sending time.
I will try in my computer and see the result and let you know result.
Example message please zip and email to ivar@lumisoft.ee .
Oh also don't dink too lot today ... try not yo sleep this yea down
|
|
|
|
|
When loading a .msg file with Mail_Message.ParseFromFile, the BCC addresses aren't returned.
Am I missing something?
|
|
|
|
|
Hi,
I just tried with my message, Bcc parsed ok.
1) There can be 2 things, you old version.
2) There is something wrong with message.
|
|
|
|
|
1. I'm using the latest version that can be downloaded off of your site. Do I need to download and build from SVN?
2. Here's the content of the .msg file
X-Sender: from@test.com
X-Receiver: to_njbrad007@optonline.net
X-Receiver: cc_njbrad007@optonline.net
X-Receiver: bcc_njbrad007@optonline.net
X-Receiver: bcc2_njbrad007@optonline.net
X-Receiver: bcc3_njbrad007@optonline.net
MIME-Version: 1.0
From: from@test.com
To: to_njbrad007@optonline.net
Cc: cc_njbrad007@optonline.net
Date: 17 Dec 2010 19:41:27 -0500
Subject: Subject
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Body
EDIT
LumiSoft.Net.Mime.Mime.Parse finds the BCC fine, but Mail_Message.ParseFromFile() does not.
LumiSoft.Net.Mime.Mime is marked as deprecated, so I'm wary of putting it into new code.
Thanks for looking
modified on Saturday, December 18, 2010 2:33 PM
|
|
|
|
|
Hi,
You are talking about Bcc, but your posted message has no Bcc, has Cc ?????
|
|
|
|
|
That's how .Net stores the addresses. They are listed in "X-Receiver:" headers.
Mime.Parse is able to pick up the Bcc addresses stored this way, but Mail_Message.ParseFromFile is not. If Mime.Parse isn't going away, I'll use that, but the deprecated attribute has me wary.
|
|
|
|
|
Old Mime class won't parse "X-Receiver" as Bcc. Bcc is "Bcc:" header.
All X- headers are custom headers. They are pared to header fileds collection, so you must look up such heders from there.
Old Mime is deprecrated and will be removed in future.
|
|
|
|
|
When I parse a file saved by .Net the Mime class is parsing out the Bcc fields from the X-Receiver headers.
It seems that every X-Receiver that isn't also a To or a Cc gets stored in the Bcc property.
|
|
|
|
|
Most BCC's are not put in a BCC: header, but instead are listed as X-Receivers that are NOT in the To: or CC: list.
Here is code I'm currently using to "rebuild" the BCC: list with X-Receivers. YMMV.
private static void FixupBcc(Mail_Message mailMessage)
{
if (mailMessage.Bcc == null)
{
mailMessage.Bcc = new Mail_t_AddressList();
}
foreach (MIME_h item in mailMessage.Header["X-Receiver"])
{
var receiver = item.ValueToString();
if (String.IsNullOrWhiteSpace(receiver) == false)
{
var list = Mail_t_AddressList.Parse(receiver);
if ((list != null) && (list.Mailboxes != null) && (list.Mailboxes.Count() > 0))
{
string address = list.Mailboxes[0].Address;
if (String.IsNullOrWhiteSpace(address) == false)
{
Mail_t_Address maddress = null;
if ((mailMessage.To != null) && (mailMessage.To.Mailboxes != null))
{
maddress = mailMessage.To.Mailboxes.Where(mb => String.Compare(mb.Address, address, StringComparison.InvariantCultureIgnoreCase) == 0).FirstOrDefault();
}
if ((maddress == null) && (mailMessage.Cc != null) && (mailMessage.Cc.Mailboxes != null))
{
maddress = mailMessage.Cc.Mailboxes.Where(mb => String.Compare(mb.Address, address, StringComparison.InvariantCultureIgnoreCase) == 0).FirstOrDefault();
}
if (maddress == null)
{
string displayname = list.Mailboxes[0].DisplayName;
mailMessage.Bcc.Add(new Mail_t_Mailbox(displayname, address));
}
}
}
}
}
}
|
|
|
|
|
Hi,
I just want to send simply mail with attachment. I use code below, and i get an error SERVER_FAILURE when i call method Connect(host, port). Source of error is in DNS_Client class, method Resolve(string hostName_IP). What should i do?
Mime message = new Mime();
MimeEntity main = message.MainEntity;
main.Subject = Subject;
main.From = new AddressList() { new MailboxAddress(this.Adress) };
main.ContentType = MediaType_enum.Multipart_mixed;
MimeEntity attachment = main.ChildEntities.Add();
attachment.ContentType = MediaType_enum.Application_octet_stream;
attachment.ContentDisposition = ContentDisposition_enum.Attachment;
attachment.ContentTransferEncoding = ContentTransferEncoding_enum.Base64;
attachment.ContentDisposition_FileName = Patch;
attachment.DataFromFile(Patch);
MemoryStream msgStr = new MemoryStream();
message.ToStream(msgStr);
SmtpClientEx myClient = new SmtpClientEx();
myClient.Connect(this.m_host, 587);
myClient.Authenticate(this.m_user, this.m_pass);
myClient.SendMessage(msgStr);
|
|
|
|
|
Hi,
Probably for start you should use latestst "nowdays" code .... codeproject code over 5 years old.
Latest code is:
http://www.lumisoft.ee/lswww/download/downloads/[^]
There is also example apps folder, there are some example application ... .
If not useful, let me know.
|
|
|
|
|
The problem was becouse of the old version.
Now I have the newest one, but I still have some problems. I want to send SIMPLE message, which contains attachment(the file) and the 'basics'. I don't need text in it, but the simplest things like: from, to, subject. Could you please show me the short code which would give me that possibility? Im trying to do that for hours, but I know you are the creator of that stuff, so it would be probably a minute for you.
In smtp_client_app you use long methods which I just can't undearstand.
Thank you very much for help.
|
|
|
|
|
|
Thank you very much for help.
I did as you said and I have even found a mistake you have made in examples of creating messages. Function: Create_AttachmentOnly()
is:
application_octetStream.SetDataFromFile("attachment.txt",MIME_TransferEncodings.Base64);
msg.Body = application_octetStream;
should probably be reversed:
msg.Body = application_octetStream;
application_octetStream.SetDataFromFile(Patch, MIME_TransferEncodings.Base64);
I still have a problem. I create the message with your method, there is an attachment in it, everything is fine but then I call method
SMTP_Client.QuickSendSmartHost(null, m_host, m_port, false, m_user, m_pass,
Adress, new string[] { To }, msgStr);
to send my mail. In debug mode the code goes through this method till the end, to do the line:
smtp.SendMessage(message);
Then it goes through and reaches the line:
long writtenCount = this.TcpStream.WritePeriodTerminated(message);
And here is the problem. The writtenCount veriable is still 0 after the line above. Of course the stream 'message' exist and is full of data, it's length is 5739883. The messages are sended, but they are totally empty. Do you have any idea what is the reason of this?
|
|
|
|
|
I assume you pass message as stream, but won't reset message position to "0" before passing it to send method.
As send documentation says, "sending starts from stream current position".
|
|
|
|
|
Thank you very much. You are right. My bad. I really appreciate your work.
Greetings.
|
|
|
|