如何设置从地址到任何电子邮件其他gmail(通过Gmail发送电子邮件)?

编程入门 行业动态 更新时间:2024-10-27 02:28:57
本文介绍了如何设置从地址到任何电子邮件其他gmail(通过Gmail发送电子邮件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在这篇文章中,在.NET中通过Gmail发送电子邮件我们有一个代码通过gmail发送电子邮件,发送邮件我们发现从字段包含我使用的Gmail帐户 我使用相同的代码,但通过将发件人地址更改为任何电子邮件我想要设置gmail地址在凭据如下所示

In this post Sending Email in .NET Through Gmail we have a code to send email through gmail, in the send mail we find from Field contain gmail account that I used I use the same code but by changing the From Address to any email I want ans set gmail address in Credentials as bellow

var fromAddress = new MailAddress("AnyEmai@mailserver", "From Name"); var toAddress = new MailAddress("to@example", "To Name"); const string fromPassword = "fromPassword"; const string subject = "Subject"; const string body = "Body"; var smtp = new SmtpClient { Host = "smtp.gmail", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential("from@gmail", fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); }

但是发送的电子邮件Gmail帐户仍然显示在发件人地址和 AnyEmai@mailserver 不出现...有什么办法吗?

But in the sent email gmail account still appear in From Address and AnyEmai@mailserver not appear ... is there any way to do that ?

推荐答案

您可以使用邮件设置>>帐户和导入选项在邮件帐户中导入电子邮件ID,可用于发送邮件,但如果您想每次使用随机电子邮件ID发送邮件不可能。 Gmail会将其视为欺骗/垃圾邮件,并在发送邮件之前将邮件地址重置为原始邮件ID。

You can import an email id in your gmail account using Mail Settings >> Accounts and Import options and that can be used for sending the mails, however if you are want to use some random email id everytime to send the mails it is not possible. Gmail will treat that as a spoofing/spam and it will reset the mail address to your original mail id before sending the mail.

using System.Net; using System.Net.Mail; public void email_send() { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail"); mail.From = new MailAddress("from@gmail"); mail.To.Add("to@gmail"); mail.Subject = "Your Subject"; mail.Body = "Body Content goes here"; System.Net.Mail.Attachment attachment; attachment = new System.Net.Mail.Attachment("c:/file.txt"); mail.Attachments.Add(attachment); SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("from@gmail", "mailpassword"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); }

还有许多其他邮件服务可以从中实现相同但不能通过gmail。结帐博客通过Gmail发送电子邮件至.NET 发送邮件使用不同的属性。

There are many other mail services from which you can achieve the same but not through the gmail. Checkout the blog Send email in .NET through Gmail for sending mail using different properties.

更多推荐

如何设置从地址到任何电子邮件其他gmail(通过Gmail发送电子邮件)?

本文发布于:2023-10-07 10:28:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469140.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何设置   发送电子邮件   电子邮件   地址   gmail

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!