Esempio n. 1
0
        public void sendAttachedFile(string filename, byte[] data, bool bTilPBS)
        {
            string local_filename = filename.Replace('.', '_') + ".txt";

            string SmtpUsername = m_dbData3060.GetSysinfo("SMTPUSER");
            string SmtpPassword = m_dbData3060.GetSysinfo("SMTPPASSWD");
            var    smtp         = new SmtpClient
            {
                Host                  = m_dbData3060.GetSysinfo("SMTPHOST"),
                Port                  = int.Parse(m_dbData3060.GetSysinfo("SMTPPORT")),
                EnableSsl             = bool.Parse(m_dbData3060.GetSysinfo("SMTPSSL")),
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(SmtpUsername, SmtpPassword)
            };

            MailMessage email = new MailMessage();

            if (bTilPBS)
            {
#if (DEBUG)
                email.Subject = "Test Til PBS: " + local_filename;
                email.Body    = "Test Til PBS: " + local_filename;
#else
                email.Subject = "Til PBS: " + local_filename;
                email.Body    = "Til PBS: " + local_filename;
#endif
            }
            else
            {
#if (DEBUG)
                email.Subject = "Test Fra PBS: " + local_filename;
                email.Body    = "Test Fra PBS: " + local_filename;
#else
                email.Subject = "Fra PBS: " + local_filename;
                email.Body    = "Fra PBS: " + local_filename;
#endif
            }

            email.To.Add(new MailAddress(m_dbData3060.GetSysinfo("MAILTOADDR"), m_dbData3060.GetSysinfo("MAILTONAME")));
            email.From    = new MailAddress(m_dbData3060.GetSysinfo("MAILFROM"));
            email.ReplyTo = new MailAddress(m_dbData3060.GetSysinfo("MAILREPLY"));
            email.Attachments.Add(new Attachment(new MemoryStream(data), local_filename, "text/plain"));
            smtp.Send(email);
        }
Esempio n. 2
0
        public void overfoersel_mail(dbData3060DataContext p_dbData3060, int lobnr)
        {
            var antal = (from c in p_dbData3060.tbltilpbs
                         where c.id == lobnr
                         select c).Count();

            if (antal == 0)
            {
                throw new Exception("101 - Der er ingen PBS forsendelse for id: " + lobnr);
            }

            string SmtpUsername = p_dbData3060.GetSysinfo("SMTPUSER");
            string SmtpPassword = p_dbData3060.GetSysinfo("SMTPPASSWD");
            var    smtp         = new SmtpClient
            {
                Host                  = p_dbData3060.GetSysinfo("SMTPHOST"),
                Port                  = int.Parse(p_dbData3060.GetSysinfo("SMTPPORT")),
                EnableSsl             = bool.Parse(p_dbData3060.GetSysinfo("SMTPSSL")),
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(SmtpUsername, SmtpPassword)
            };


            var qrykrd = from k in p_dbData3060.tblMedlems
                         join h in p_dbData3060.tbloverforsels on k.Nr equals h.Nr
                         where h.tilpbsid == lobnr
                         select new
            {
                k.Nr,
                k.Email,
                k.Kaldenavn,
                k.Navn,
                h.betalingsdato,
                h.advistekst,
                h.advisbelob,
                h.bankregnr,
                h.bankkontonr,
            };


            // Start loop over betalinger i tbloverforsel
            int testantal = qrykrd.Count();

            foreach (var krd in qrykrd)
            {
                //  Create a new email object
                MailMessage email = new MailMessage();

#if (DEBUG)
                email.Subject = "TEST Bankoverførsel fra Puls 3060: skal sendes til " + p_dbData3060.GetSysinfo("MAILTONAME") + " - " + p_dbData3060.GetSysinfo("MAILTOADDR");
                email.To.Add(new MailAddress(p_dbData3060.GetSysinfo("MAILTOADDR"), p_dbData3060.GetSysinfo("MAILTONAME")));
#else
                email.Subject = "Bankoverførsel fra Puls 3060";
                if (krd.Email.Length > 0)
                {
                    email.To.Add(new MailAddress(krd.Email, krd.Navn));
                    email.Bcc.Add(new MailAddress(p_dbData3060.GetSysinfo("MAILTOADDR"), p_dbData3060.GetSysinfo("MAILTONAME")));
                }
                else
                {
                    email.Subject += ": skal sendes til " + krd.Navn;
                    email.To.Add(new MailAddress(p_dbData3060.GetSysinfo("MAILTOADDR"), p_dbData3060.GetSysinfo("MAILTONAME")));
                }
#endif
                email.Body = new clsInfotekst
                {
                    infotekst_id     = 40,
                    numofcol         = null,
                    kaldenavn        = krd.Kaldenavn,
                    betalingsdato    = krd.betalingsdato,
                    advisbelob       = krd.advisbelob,
                    bankkonto        = krd.bankregnr + "-" + krd.bankkontonr,
                    advistekst       = krd.advistekst,
                    underskrift_navn = "\r\nMogens Hafsjold\r\nRegnskabsfører"
                }.getinfotekst(p_dbData3060);

                email.From = new MailAddress(p_dbData3060.GetSysinfo("MAILFROM"));
                email.ReplyToList.Add(new MailAddress(p_dbData3060.GetSysinfo("MAILREPLY")));

                smtp.Send(email);
            }
        }