title: save copy of mail that i send lotus notes (using script)
body: <p><strong>Question:</strong></p>
  
  <ol>
  <li>How to save a copy of mail that i send using lotus notes (if using
  script)</li>
  <li>Do i need to copy maildoc, using copyallitem and then put it
      inside the folder (send mail).</li>
  </ol>
  
  <p>Below is my sample agent i write of sending mail, but i have problem to make a copy of sent mail!</p>
  
  <pre><code>Option Public
  
  Dim body As NotesMIMEEntity
  Dim stream As NotesStream
  Sub Initialize
      Dim ss As New NotesSession
      Dim db As NotesDatabase
      Dim vw As NotesView
      Dim maildb As NotesDatabase
  
      Dim ec As NotesViewEntryCollection
      Dim entry As NotesViewEntry
      Dim doc As NotesDocument
  
      Dim maildoc As NotesDocument
      Dim body As NotesMIMEEntity, header As NotesMIMEHeader, stream As NotesStream
      Dim child As NotesMIMEEntity
  
  '   Dim nam As NotesName
  '   Dim principal As String
  
  '   Set nam = ss.CreateName("LSBS Admin")
  '   principal = nam.Common
  
      email$="TestUser1@devsvr1.pcs.com.my"
  
      Dim rtBody As NotesRichTextItem
  
      Set db=ss.Currentdatabase
      Set vw=db.getview("(test send mail)")
  
      Set maildb = ss.getdatabase (db.server, "mail.box") 'Get Mailbox on server
  
      Set ec = vw.Allentries
      Set entry=ec.getfirstentry
  
      Do While Not entry Is Nothing
          Set doc = entry.Document
          Set stream = ss.Createstream()
          ss.Convertmime = False
          Set maildoc = maildb.Createdocument()
  
          maildoc.Form = "Memo"
          maildoc.Principal = "LSBSAdmin@surveyboardsarawak.com"  'principal
  
          maildoc.SendTo = email$
          maildoc.Recipients = maildoc.sendto
  
          Set body = maildoc.Createmimeentity
  
          Set header = body.Createheader("Subject")   '   subject
          Call header.Setheaderval("Test send mail to folder")
  
  
          Call stream.Writetext(|&lt;html&gt;&lt;body&gt;|)
          Call stream.Writetext(|&lt;b&gt;Dear Sir,&lt;/b&gt;&lt;br&gt;|)
          Call stream.Writetext(|&lt;p&gt; Thank you &lt;/p&gt;|)
          Call stream.Writetext(|&lt;p&gt; &lt;/p&gt;|)
          Call stream.Writetext(|Secretary&lt;br&gt;|)
          Call stream.Writetext(|Land Surveyors Board Sarawak&lt;br&gt;|)
          Call stream.Writetext(|&lt;em&gt;(No signature is required on this computer generated document)&lt;/em&gt;&lt;br&gt;|)
          Call stream.Writetext(|&lt;/body&gt;&lt;/html&gt;|)
          Set child = body.Createchildentity()    'insert the email content
          Call child.Setcontentfromtext(stream, "text/HTML;charset=iso-8859-1", ENC_NONE)
          Call stream.Close()
          Call stream.Truncate()
  %rem        
          Set child = body.Createchildentity()    'attach the excel into the email
          Set header = child.Createheader("Content-Type")
          Call header.Setheaderval("multipart/mixed")
          Set header = child.Createheader("Content-Disposition")
          Call header.Setheaderval(|attachment; filename="| + xlfilename + |"|)
          Set header = child.Createheader("Content-ID")
          Call header.Setheaderval(|"| + xlfilename + |"|)
          Set stream = ss.Createstream()
  
          Call child.Setcontentfrombytes(stream, "application/vnd.ms-excel", ENC_IDENTITY_BINARY)
          Call stream.Close()
          Call stream.Truncate()
  %end rem        
          Call maildoc.save(False,False) '    send mail
      '   Call maildoc.Send(False)
          ss.Convertmime = True   
  
          Set entry = ec.Getnextentry(entry)
      Loop
  
  End Sub
  </code></pre>
  
  <p>Attach photo is result of mail</p>
  
  <p><a href="https://i.stack.imgur.com/PmBMJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PmBMJ.jpg" alt="want to store fake user"></a></p>
  
  <p>I using Basic Notes
  Click File > Preferences > User Preferences.</p>
  
  <p>Under Sending, click one of the options in the Save copies of messages that I send field.
  Always - to save all messages you send in the Sent view.
  Never - never save messages you send in the Sent view
  Ask me - get prompted to save each message you send when you send it. If you click Yes when asked to save a message, the message is saved in the Sent view</p>
  
  <p>Setting doesn't help me save the email that i sent.</p>
  
  <p><strong>Coding updated as suggestion, i might forgot some part of the code, if possible can you point me which part is wrong. Thanks</strong></p>
  
  <pre><code>Option Public
  
  Dim body As NotesMIMEEntity
  Dim stream As NotesStream
  Sub Initialize
      Dim ss As New NotesSession
      Dim db As NotesDatabase
      Dim vw As NotesView
      Dim maildb As NotesDatabase
  
      Dim ec As NotesViewEntryCollection
      Dim entry As NotesViewEntry
      Dim doc As NotesDocument
  
      Dim maildoc As NotesDocument
      Dim body As NotesMIMEEntity, header As NotesMIMEHeader, stream As NotesStream
      Dim child As NotesMIMEEntity
  
  
      email$="TestUser1@devsvr1.pcs.com.my"
  
      Dim rtBody As NotesRichTextItem
  
      Set db=ss.Currentdatabase
      Set vw=db.getview("(test send mail)")
  
      Set maildb = New NotesDatabase( "" , "" )
      Call maildb.openMail()
  
      Set ec = vw.Allentries
      Set entry=ec.getfirstentry
  
      Do While Not entry Is Nothing
          Set doc = entry.Document
          Set stream = ss.Createstream()
          ss.Convertmime = False
          Set maildoc = maildb.Createdocument()
  
          maildoc.Form = "Memo"
  
          maildoc.From = "LSBSAdmin@somedomain.com@surveyboardsarawak.com"  'from
          maildoc.Principal = "LSBSAdmin@somedomain.com@surveyboardsarawak.com"  'principal
  
          maildoc.SendTo = email$
          maildoc.Recipients = maildoc.sendto
  
          Set body = maildoc.Createmimeentity
  
          Set header = body.Createheader("Subject")   '   subject
          Call header.Setheaderval("Test send mail to folder")
  
  
          Call stream.Writetext(|&lt;html&gt;&lt;body&gt;|)
          Call stream.Writetext(|&lt;b&gt;Dear Sir,&lt;/b&gt;&lt;br&gt;|)
          Call stream.Writetext(|&lt;p&gt; Thank you &lt;/p&gt;|)
          Call stream.Writetext(|&lt;p&gt; &lt;/p&gt;|)
          Call stream.Writetext(|Secretary&lt;br&gt;|)
          Call stream.Writetext(|Land Surveyors Board Sarawak&lt;br&gt;|)
          Call stream.Writetext(|&lt;em&gt;(No signature is required on this computer generated document)&lt;/em&gt;&lt;br&gt;|)
          Call stream.Writetext(|&lt;/body&gt;&lt;/html&gt;|)
          Set child = body.Createchildentity()    'insert the email content
          Call child.Setcontentfromtext(stream, "text/HTML;charset=iso-8859-1", ENC_NONE)
          Call stream.Close()
          Call stream.Truncate()
  
          maildoc.SaveMessageOnSend = True
          Call maildoc.Send(False)
  
          ss.Convertmime = True   
  
          Set entry = ec.Getnextentry(entry)
      Loop
  
  End Sub
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Rg9sR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Rg9sR.jpg" alt="new result"></a></p>
  
  <p>Agent signer is devadmin, which i don want let user know is this user send out the email</p>
  
  <p><a href="https://i.stack.imgur.com/537uv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/537uv.jpg" alt="agent signer"></a></p>
  
  <p><strong>Attached photo for domain</strong></p>
  
  <p><a href="https://i.stack.imgur.com/OoAWf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OoAWf.jpg" alt="enter image description here"></a></p>