如何使用Visual Studio 2010发送电子邮件并且我想更改发件人地址? [英] How To Send An Email Using Visual Studio 2010 And In That I Want to Change the From Address?

查看:234
本文介绍了如何使用Visual Studio 2010发送电子邮件并且我想更改发件人地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想知道代码或方式,我设计了使用c#发送电子邮件,因为我想更改收件人可见的发件人地址。例如:

如果我从sar@gmail.com发送消息到sss@gmail.com意味着。

sss@gmail.com从dss @收到消息gmail.com而不是sar@gmail.com。

如何通过地址更改来实现此目的。我的代码是:

Hi i want to know the code or the way , that i have designed a send an email using c#, in that i want to change the from address which is visible to the recipient. for example :
if i send a message to sss@gmail.com from sar@gmail.com means.
the sss@gmail.com receive the msg from dss@gmail.com instead of sar@gmail.com.
how to make this from address changes .my code is:

try
            {
                MailMessage Msg = new MailMessage();
                // Sender e-mail address.
                Msg.From = new MailAddress(txtUsername.Text);
                // Recipient e-mail address.
                Msg.To.Add(txtTo.Text);
                Msg.Subject = txtSubject.Text;
                Msg.Body = txtBody.Text;
                // your remote SMTP server IP.
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.Credentials=new System.Net.NetworkCredential(txtUsername.Text,txtpwd.Text);
                smtp.EnableSsl = true;
                smtp.Send(Msg);
                Msg = null;
<pre lang="xml">Page.RegisterStartupScript("UserMsg", "<script>alert('Mail sent thank you...');if(alert){ window.location='default.aspx';}</script>");
            }
            catch (Exception ex)
            {
            Console.WriteLine("{0} Exception caught.", ex);



}

}


}
}

推荐答案

简答题是否,你不能这样做。

查看此答案 [ ^ ]但您可以使用该地址向Gmail帐户发送另一个电子邮件地址。 查看此链接以获取更多信息。 [ ^ ]
Short Answer is No, you can't do this.
check This Answer[^] but you can add another email address to your Gmail account send using that. check this Link for more information.[^]


您将添加一个属性



MailMessage mailMessage = new MailMessage(mailMessageModel.From,mailMessageModel.To);

MailAddress SenderID = new MailAddress(maheshpatil4357@gmail.com);

mailMessage.Sender = SenderID;





或需要制作电子邮件设置动态类似

设置电子邮件,密码,端口和主机将其存储在数据库中

然后从数据库放入邮件消息
You Will Add One Properties

MailMessage mailMessage = new MailMessage(mailMessageModel.From, mailMessageModel.To);
MailAddress SenderID = new MailAddress("maheshpatil4357@gmail.com");
mailMessage.Sender = SenderID;


Or U need Make Email setting Dynamic Like
Set Email,Password,Port and Host Store it in Database
and Then Put Into Mail Message From Database


这篇关于如何使用Visual Studio 2010发送电子邮件并且我想更改发件人地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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