Autor Beitrag
estrella1410
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46



BeitragVerfasst: Mi 05.12.07 13:45 
Hallo,

brauche mal dringend Hilfe...habe unten meinen Code auch mal dazu gepackt...

also folgendes Problem...habe eine Form, aufgebaut wie ne E-mail und möchte diese nun per smtp versenden, wobei die namen (mailadressen) aus der textdatei ausgelesen werden (is unter name gespeichert)..

ich weis einfach nicht weiter wie ich das mit dem senden hinkriege...bin auch nich soooo erfahren...

hoffe ihr könnt mir helfen..

Gruß Jessy

im Folgenden der Code:

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using email.Properties;
using System.Net.Mail;

namespace email
{
    public partial class Form1 : Form
    {
        string name, dummy, mail, mail2, emailarchivierung;

        public Form1()
        {

            emailarchivierung = Settings.Default.emailarchivierung;
            

            InitializeComponent();
        }

        private void btnAnhang_Click(object sender, EventArgs e)
        {
            //nur PDF anzeigen; PDF Datei auswählen;
            name = Settings.Default.name;
            StreamReader sr_log = new StreamReader(name);

   
            dummy = sr_log.ReadLine();
            txtbcc.Text = (dummy + ";");


            openFile.Filter = "nurPDF|*.pdf";

            if (openFile.ShowDialog() == DialogResult.OK)
            {
                lblanhang.Text = ("Folgende Datei wurde angehängt: " + openFile.FileName);
                lblanhang.Visible = true;
            }

            //Namen ins BCC feld
        }

        private void btnSenden_Click(object sender, EventArgs e)
        {


            StreamWriter sw_log = new StreamWriter(emailarchivierung);
            sw_log.WriteLine(dummy);
            sw_log.Close();
 
            StreamReader sr_log = new StreamReader(name); 

            do
            {

               
                SmtpClient client = new SmtpClient("abc.xyz.loc");
                client.Send();
            }
            while (sr_log.EndOfStream == false);
        }
    }


        //private void txtbcc_TextChanged(object sender, EventArgs e)
        //{

        //}
    }


Moderiert von user profile iconjasocul: C#-Tags hinzugefügt
Moderiert von user profile iconjasocul: Topic aus C# - Die Sprache verschoben am Mi 05.12.2007 um 12:52
maro158
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35



BeitragVerfasst: Do 06.12.07 14:04 
Ich fürchte, Dein Code wird so keine E-Mails versenden können... Guck Dir mal vielleicht folgende Links an:

1. msdn2.microsoft.com/...lestream(VS.80).aspx
2. msdn2.microsoft.com/...mail.smtpclient.aspx
estrella1410 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46



BeitragVerfasst: Fr 07.12.07 08:38 
also ich habe mir die links mal angesehen und auch versucht das auf meinen code zu ändern aber ich komme absolut nicht weiter...kannst du mir nicht mal nen paar beispiele nennen was bei mir falsch is oder wo ich umdenken muss...hab echt grad nen brett vorm kopf...


habe mittlerweile den einen teil so geändert:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
            string SmtpMail;

            MailMessage myMessage = new MailMessage();
            myMessage.To = "Jassy.Pi@xyz.de";
            myMessage.From = "Jessica.Pi@abc.de";
            myMessage.Subject = "Hallo";
            myMessage.Priority = MailPriority.High;
            myMessage.Body = "Dies ist die Nachricht!";

            
            SmtpMail.SmtpServer = "abc.xyz.loc";
            SmtpMail.Send(myMessage);

gruß

Moderiert von user profile iconChristian S.: Code- durch C#-Tags ersetzt
maro158
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35



BeitragVerfasst: Sa 15.12.07 12:09 
Sorry, ich hatte Deine Antwort irgendwie übersehen. Das sollte funktionieren:


ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
using System;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;

namespace EmailViaSmtp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string userName = "Jessica.Pi";
            string password = "geheim";

            try
            {
                MailMessage myMessage = new MailMessage();
                myMessage.To.Add("Jassy.Pi@xyz.de");
                myMessage.From = new MailAddress("Jessica.Pi@abc.de""Jessica");
                myMessage.Subject = "Hallo";
                myMessage.Priority = MailPriority.High;
                myMessage.Body = "Dies ist die Nachricht!";

                SmtpClient client = new SmtpClient("smtp.yourserver.com");
                client.Credentials = new System.Net.NetworkCredential(userName, password);

                client.Send(myMessage);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}