Usage VB: Dim em As New "password", "Subject Text", "Body Text") S.Credentials = New Net.NetworkCredential((), password)Įmail em = new "password", "Subject Text", "Body Text") S.DeliveryMethod = SmtpDeliveryMethod.Network Sub NewHeadlessEmail(fromEmail As String, password As String, toAddress As String, subject As String, body As String) MyMail.From = new MailAddress(fromEmail) Public void NewHeadlessEmail(string fromEmail, string password, string toAddress, string subject, string body) If sending via your GMail Account ensure that Allow less secure apps is enabled from your control panel This code was tested and working as of 11 July 2018. I am posting this code to include some of the useful comments posted by other users such as Using Statements and newer methods where some answers have obsolete methods. I realise this is an answer to a very old question, with lots of other good answers. The current process security context is used to through the sendusername and sendpassword fields. When using this option you have to provide the user name and password smtpauthenticate: Specifies the mechanism used when authenticating sendusing: cdoSendUsingPort, value 2, for sending the message using String pAttachmentPath = string.Empty //No Attachments MailFormat pFormat = MailFormat.Text //Text Message String pTo = "ToAddress" pSubject = "Test From Gmail" String pGmailEmail = pGmailPassword = "GmailPassword" While Googling, I came across a similar code, that worked for me. While executing the application the control stopped indefinitely at the statement smtp.Send(mail) I tried the above C# code to send mail from Gmail to my Corporate ID.
0 Comments
Leave a Reply. |