Click here to Skip to main content
16,015,559 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
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
C#
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

C#
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 :)


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:

C#
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:
C#
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

1 solution

I guess the uids are not in correct E-mail format.

Refer to know How to: Verify that Strings Are in Valid Email Format[^].
 
Share this answer
 
Comments
Member 9744486 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 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900