发送带有用户定义对象的电子邮件 [英] Sending a Email with user defined objects

查看:104
本文介绍了发送带有用户定义对象的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我所拥有的是一个简单的登录表单,当用户在其中输入信息时,它会将包含该信息的电子邮件发送到我的电子邮件中,在那里我可以使用该信息更新服务器数据库,当前该数据库没有运行错误,但电子邮件未发送,任何机构都可以帮助我吗?
这是我到目前为止所拥有的.请修改.


Hey guys so what I have is a simple login form wich when the user inputs there information in to it it send an email with there info to my email where i can update my server data base with that info currently its runs with no errors but the email does not send can any body help me out?
Heres what i have so far. Please modify.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
using System.Net;

namespace login
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Creates a new instance of the generator class(form)
            Generator genForm = new Generator();

            //The mail address
            MailAddress ma = new MailAddress("emailHere@yahoo.com");
            const string passWord = "Password Here";
            //SMTP client thru which it will send the mail
            SmtpClient smtp = new SmtpClient
            {
                Host = "smtp.mail.yahoo.com",
                Port = 465,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(ma.Address, passWord)
            };

            string body = "Username: " + userTextBox.Text + "\n" +
                "Password: " + pwTextBox.Text;

            //Message which will get sent
            MailMessage mm = new MailMessage(ma, ma)
            {
                Subject = "My Subject",
                Body = body
            };
            //Send it
            smtp.Send(mm);
            //Makes the generator form show up.
            genForm.Show();
        }

            }
    }
}


只是为了清除它,当用户单击login


Just to clear up it send the information when the user clicks login

推荐答案

时,发送信息.检查此代码将有助于您发送邮件.
如果您想从Gmail帐户发送邮件,则Gmail的SmtpClient为
check this code it will help you to send the mail.
if you want''s to send mail from Gmail Account then SmtpClient of Gmail is
smtp.gmail.com





System.Net.Mail.MailAddress From = new System.Net.Mail.MailAddress("SenderMailID");
System.Net.Mail.MailAddress To = new System.Net.Mail.MailAddress("YourMail_ID");
System.Net.Mail.MailMessage Message = new System.Net.Mail.MailMessage(From, To);
Message.Subject = "Write Subject For Mail";
Message.Body = "Write body of Mail";
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.mail.yahoo.com");
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential(txtfrom.Text, txtpass.Text);
client.Send(Message);
MessageBox.Show("Send Email Successfully");


这篇关于发送带有用户定义对象的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆