Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Halo everybody,
 
Ich have a question about an exception.
 
I want to write an C# program thath send mails with attachments and on the client site it should download this.
 
Sender
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
 
                string mailAdress = "update@xxxx.de";
 
                mailMessage.From= new MailAddress(mailAdress.Trim());
                mailMessage.To.Add(GetCostumer());
                mailMessage.Subject = textBox1.Text;
 
 
                foreach (var fileInfo in files)
                {
                    Attachment myAttech = new Attachment(fileInfo.FullName);
                    mailMessage.Attachments.Add(myAttech);
                }
 
                SmtpClient client = new SmtpClient("smtp.1und1.de", Convert.ToInt32("25"));
                client.Credentials = new NetworkCredential(mailAdress.Trim(), "PWXXX");
                client.Send(mailMessage);
                CommitButton.BackColor = Color.Green;

So far it's great. The sender send the mail with the attachments.
 
But when the mail downloader want to download the mail with attachments I get an excpetion:
 
The given string does not contains for the E-Mail-Adress required format
 

 

Code for downloading mail.
I use for downloading the S22.dll
 
private string GetVersions()
          {
            string versions = String.Empty;          
            using (ImapClient client = new ImapClient("imap.1und1.de", Convert.ToInt32("993"), "XXX@XXX.de", "PWXXX", AuthMethod.Auto, true))
            {
                Trace.WriteLine("Connected to Server");
                var uids = client.Search(SearchCondition.All()); 
                foreach (var uid in uids)
                {
                    Trace.WriteLine(uid);
                }
                var messages = client.GetMessages(uids); <----EXCEPTION
 
                foreach (var mail in messages)
                {
                    var header = mail.Headers["Subject"];
 
                    if (header.Contains("Version"))
                    {
                        _uid = mail.Headers["Message-ID"];
                        Trace.WriteLine(header.ToString());
                        versions = header.Trim().Split('n').Last().Trim();
                    }
                }
                return
              }


Surly my code is not CleanCode. But i just test this mechanism.
 
I hope someone can help me Smile | :)
 

matias
 

Auf Deutsch
Hallo zusammen,
 
nun sitze ich hier seit Stunden und weiß nicht weiter.
 
Mein Ziel ist es Emails mit Anhang zu versenden und wieder abzurufen.
Versenden klappt soweit. Hier ein ausschnitt aus dem Code:
 
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
 
                string mailAdress = "update@xxxx.de";
 
                mailMessage.From= new MailAddress(mailAdress.Trim());
                mailMessage.To.Add(GetCostumer());
                mailMessage.Subject = textBox1.Text;
 
 
                foreach (var fileInfo in files)
                {
                    Attachment myAttech = new Attachment(fileInfo.FullName);
                    mailMessage.Attachments.Add(myAttech);
                }
 
                SmtpClient client = new SmtpClient("smtp.1und1.de", Convert.ToInt32("25"));
                client.Credentials = new NetworkCredential(mailAdress.Trim(), "PWXXX");
                client.Send(mailMessage);
                CommitButton.BackColor = Color.Green;

Email Wird auch versendet mit Anhang. Kann sie über den 1und1 Mailbrowser sehen. Soweit Super! oder auch nicht.
 

Nun beim Abrufen der Email erhalte ich eine Exception:
"Die angegebene Zeichenfolge besitzt nicht das für eine E-Mail-Adresse erforderliche Format."
 

Code für das Abrufen der Mails:
private string GetVersions()
          {
            string versions = String.Empty;          
            using (ImapClient client = new ImapClient("imap.1und1.de", Convert.ToInt32("993"), "XXX@XXX.de", "PWXXX", AuthMethod.Auto, true))
            {
                Trace.WriteLine("Connected to Server");
                var uids = client.Search(SearchCondition.All()); 
                foreach (var uid in uids)
                {
                    Trace.WriteLine(uid);
                }
                var messages = client.GetMessages(uids); <----EXCEPTION
 
                foreach (var mail in messages)
                {
                    var header = mail.Headers["Subject"];
 
                    if (header.Contains("Version"))
                    {
                        _uid = mail.Headers["Message-ID"];
                        Trace.WriteLine(header.ToString());
                        versions = header.Trim().Split('n').Last().Trim();
                    }
                }
                return
              }


*Natürlich ist der Code noch nicht Clean. Ich teste gerade mit dem Code ein wenig.
 
Ich hoffe jemand hat eine Idee und kann mir weiterhelfen.
 
Schönen Abend euch
 
Gruß matias
Posted 4-Jul-13 8:27am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I guess the uids are not in correct E-mail format.
 
Refer to know How to: Verify that Strings Are in Valid Email Format[^].
Comments
Member 9744486 at 4-Jul-13 16:47pm
   
Hi
 
I have just looked at the UID's.
I can't see anything what should be wrong.
 
The UID's looks like this:
 
[0]9
[1]11
 
I think the S22.Imap check this, if they are in correct format, or?
 
But I will still look at this problem.
Member 9744486 at 4-Jul-13 16:51pm
   
Stacktrace
 
[6736] System.FormatException: Die angegebene Zeichenfolge besitzt nicht das für eine E-Mail Adresse erforderliche Format.
[6736] bei System.Net.Mail.MailAddressParser.ReadCfwsAndThrowIfIncomplete(String data, Int32 index)
[6736] bei System.Net.Mail.MailAddressParser.ParseDomain(String data, Int32& index)
[6736] bei System.Net.Mail.MailAddressParser.ParseAddress(String data, Boolean expectMultipleAddresses, Int32& index)
[6736] bei System.Net.Mail.MailAddressParser.ParseMultipleAddresses(String data)
[6736] bei System.Net.Mail.MailAddressCollection.ParseValue(String addresses)
[6736] bei System.Net.Mail.MailAddressCollection.Add(String addresses)
[6736] bei S22.Imap.MessageBuilder.ParseAddressList(String list)
[6736] bei S22.Imap.MessageBuilder.SetAddressFields(MailMessage m, NameValueCollection header)
[6736] bei S22.Imap.MessageBuilder.FromHeader(String text)
[6736] bei S22.Imap.MessageBuilder.FromMIME822(String text)
[6736] bei S22.Imap.ImapClient.GetMessage(UInt32 uid, FetchOptions options, Boolean seen, String mailbox)
[6736] bei S22.Imap.ImapClient.GetMessages(UInt32[] uids, FetchOptions options, Boolean seen, String mailbox)
[6736] bei S22.Imap.ImapClient.GetMessages(UInt32[] uids, Boolean seen, String mailbox)
[6736] bei PullUpdates.PullUpdates.GetVersions() in G:\SmartHeil\SmartHeil\PullUpdates\Program.cs:Zeile 93.
[6736] bei PullUpdates.PullUpdates.DownloadData() in G:\SmartHeil\SmartHeil\PullUpdates\Program.cs:Zeile 54.
Member 9744486 at 4-Jul-13 17:26pm
   
Also what I just find out, when the attachments contains an .exe data, the exception appears.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 4 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100