使用gmail作为smtp发送TextBox1.text值 [英] Send TextBox1.text Value using gmail as smtp

查看:85
本文介绍了使用gmail作为smtp发送TextBox1.text值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我创建了文本框,按钮发送


我想发送textbox1作为我的电子邮件正文并使用gmail smtp


<这是我的代码,但它不允许我编译它..:

使用System; 
使用System.Collections.Generic;使用System.ComponentModel
;
使用System.Data;使用System.Drawing
;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
使用System.Windows.Forms;
使用System.Net.Mail;
使用System.Net;

命名空间Ledger
{
公共部分类Form1:表格
{
public Form1()
{
InitializeComponent() ;
}

private void pictureBox1_Click(object sender,EventArgs e)
{

}

private void Form1_Load(object sender,EventArgs e)
{

}

protected void button1_Click(object sender,EventArgs e)
{
try
{
//创建要发送的msg对象
MailMessage msg = new MailMessage();
//将您的电子邮件地址添加到收件人
msg.To.Add(" eliyahugigi29@gmail.com");
//配置,我们从**发送邮件地址 - 不知道我需要这个OR NOT **
MailAddress地址=新的MailAddress?(" eliyahugigi29@gmail.com");
msg.From =地址;
//在主题的开头附加他们的名字
msg.Subject =(" New Rich Seed");
msg.Body = textBox1.Text;

//配置SmtpClient发送邮件。
SmtpClient client = new SmtpClient(" smtp.gmail.com",465);
client.EnableSsl = true;如果您的提供商需要它
//设置凭据登录到我们的发件人的电子邮件地址//只启用此("用户名","密码")
的NetworkCredential证书=新的NetworkCredential(" eliyahugigi29 @ gmail.com"," Ssgeli9988");
client.Credentials =凭证;

//发送msg
client.Send(msg);

}
}

解决方案

什么是编译器错误?它似乎错过了一个"}"以及一些代码如代码末尾的catch(异常)



Hello, i have created textbox, with button send

i want to send textbox1 as body of my email and using gmail smtp

here is my code, but it not let me compile it..:

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

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

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        protected void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //Create the msg object to be sent
                MailMessage msg = new MailMessage();
                //Add your email address to the recipients
                msg.To.Add("eliyahugigi29@gmail.com");
                //Configure the address we are sending the mail from **- NOT SURE IF I NEED THIS OR NOT?**
                MailAddress address = new MailAddress("eliyahugigi29@gmail.com");
                msg.From = address;
                //Append their name in the beginning of the subject
                msg.Subject = ("New Rich Seed");
                msg.Body = textBox1.Text;

                //Configure an SmtpClient to send the mail.
                SmtpClient client = new SmtpClient("smtp.gmail.com", 465);
                client.EnableSsl = true; //only enable this if your provider requires it
                                         //Setup credentials to login to our sender email address ("UserName", "Password")
                NetworkCredential credentials = new NetworkCredential("eliyahugigi29@gmail.com", "Ssgeli9988");
                client.Credentials = credentials;

                //Send the msg
                client.Send(msg);

            }
}

解决方案

What is the compiler error? It looks like miss one "}" and some code like catch(exception) at the end of code


这篇关于使用gmail作为smtp发送TextBox1.text值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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