通过Gmail发送电子邮件c#COM,电子邮件地址不是gmail

时间:2018-10-02 20:39:24

标签: smtp

我需要使用COM在c#中发送电子邮件。我使用了以下代码:

                var fromAddress = new MailAddress("mai@live.com", "From mai live");
                var toAddress = new MailAddress("test@apol.eu", "to test");

                const string subject = "Subject test email";
                const string body = "<h1><b>Body test email</b></h1>";

                var smtp = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential("mail@gmail.com", "mdp"),
                    Timeout = 30 * 1000,                      

                };

using (var message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = subject,
                    Body = body,
                    IsBodyHtml = true,
                    BodyEncoding = System.Text.UTF8Encoding.UTF8

            })smtp.Send(message);

此代码对我有用,但是所有收到的邮件都是来自Gmail的! 任何想法如何更改发件人地址?

0 个答案:

没有答案