如何在此代码中添加附件..请.... [英] How to add attachment in this code..Please....

查看:76
本文介绍了如何在此代码中添加附件..请....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void SendMail()
    {
        var fromAddress = "A@gmail.com";// Gmail Address from where you send the mail
        var toAddress = YourEmail.Text.ToString();
        const string fromPassword = "Password";//Password of your gmail address
        string subject = YourSubject.Text.ToString();
        string body = "From: " + YourName.Text + "\n";
        body += "Email: " + YourEmail.Text + "\n";
        body += "Subject: " + YourSubject.Text + "\n";
        body += "Message: \n" + Comments.Text + "\n";
        var smtp = new System.Net.Mail.SmtpClient();
        {
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
            smtp.Timeout = 20000;
        }
        smtp.Send(fromAddress, toAddress, subject, body);
    }

推荐答案

在这里看看:
Have a look here: Sending an Email in C# with or without attachments: generic routine.[^]

You just need to add your gmail specific bits.


这篇关于如何在此代码中添加附件..请....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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