Hi @peter liles,
First you need to make sure your code can send the email successfully, then save the Message.body after sending the email.
I think you can name the file according to the recipient's email id, or change it to your needs.
Private Sub SaveMessage(ByVal message As MailMessage)
Dim ReceiverEmailId As String = message.[To].ToString()
Dim MessBody As String = message.Body
Dim path As String = ReceiverEmailId & ".txt"
File.WriteAllText(Server.MapPath(path), MessBody)
End Sub
ALL code
Protected Sub btn_send_Click(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim client As SmtpClient = New SmtpClient()
client.UseDefaultCredentials = False
client.Credentials = New System.Net.NetworkCredential("***", "***")
client.Port = 587
client.Host = "smtp.office365.com"
client.DeliveryMethod = SmtpDeliveryMethod.Network
client.EnableSsl = True
Dim message As MailMessage = New MailMessage()
message.From = New MailAddress("***")
message.[To].Add(txtEmail.Text)
message.Subject = txtSubject.Text
message.Body = txtmessagebody.Text
message.IsBodyHtml = True
' message.AlternateViews.Add(Mail_Body())
client.Send(message)
SaveMessage(message)
Catch ex As Exception
Response.Write("Failed")
End Try
End Sub
Private Sub SaveMessage(ByVal message As MailMessage)
Dim ReceiverEmailId As String = message.[To].ToString()
Dim MessBody As String = message.Body
Dim path As String = ReceiverEmailId & ".txt"
File.WriteAllText(Server.MapPath(path), MessBody)
End Sub
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.