How to set From Address to any email other gmail in ( Sending Email in .NET Through Gmail )?

前端 未结 4 757
谎友^
谎友^ 2021-01-22 21:05

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

相关标签:
4条回答
  • 2021-01-22 21:32

    The email address needed to be verified by gmail from the account settings.

    Please find my blog post for the same describing it in detail, the steps to be followed:

    http://karmic-development.blogspot.in/2013/10/send-email-from-aspnet-using-gmail-as.html

    before following all the above steps, you need to authenticate your gmail account to allow access to your application and also the devices. Please check all the steps for account authentication at the following link:

    http://karmic-development.blogspot.in/2013/11/allow-account-access-while-sending.html

    0 讨论(0)
  • 2021-01-22 21:33

    Shall you check this question change sender address when sending mail through gmail in c#
    I think it is related to your inquiry.

    0 讨论(0)
  • 2021-01-22 21:36

    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.com");
        mail.From = new MailAddress("from@gmail.com");
        mail.To.Add("to@gmail.com");
        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.com", "mailpassword");
        SmtpServer.EnableSsl = true;
        SmtpServer.Send(mail);
    
    }
    

    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.

    0 讨论(0)
  • 2021-01-22 21:40

    It's that way by design. You have to find another way to send outbound emails so that the return address you want shows up (I've been there, there seems to be no way to spoof the from address).

    0 讨论(0)
提交回复
热议问题